2

There is a Java maven project with its source code managed by Gitbucket. Having configured a maven item in jenkins for the project.

And, now want to trigger auto build in jenkins when gitbucket receive a new commit, according to: https://plugins.jenkins.io/gitbucket

Here is what I have done:

  • Install jenkins & gitbucket.
  • Install plugins for jenkins, include git plugin & Gitbucket plugin.
  • In githucket, add a webhook of jenkins.
  • In jenkins, create a maven project, and checked the option Build when a change is pushed to GitBucket within Build Triggers section.

Current status:

  • Could build the project in jenkins by hand successfully.

  • But, when push a new commit to gitbucket, jenkins can't trigger a new build.

  • In gitbucket's webhook config page, when click test hook, would get a 403 response.

Questions:

  • When push from gitbucket to jenkins on commit, what is the mechanism to do authentication? How to config it in details. (I have googled a while, didn't get a clear working solution)
  • In gitbucket, when create webhook, there is a security token field, where should the value from, is that relevant to this task?

Thanks.

Eric
  • 22,183
  • 20
  • 145
  • 196
  • What url do you specify as a webhook url on GitBucket? – Naoki Takezoe Apr 01 '18 at 05:38
  • @NaokiTakezoe It's `http://localhost:8282/jenkins/gitbucket-webhook/`, with `localhost:8282` as jenkins's home. – Eric Apr 01 '18 at 07:54
  • 1
    If your Jenkins is working at `http://localhost:8282/`, try to set `http://localhost:8282/gitbucket-webhook/` as a webhook url. Maybe `/jenkins/` is unnecessary. – Naoki Takezoe Apr 01 '18 at 08:29
  • @NaokiTakezoe Yes, after changing it to `http://localhost:8282/gitbucket-webhook/`, click `test hook` would return `200`, thanks. – Eric Apr 01 '18 at 08:51
  • @NaokiTakezoe Though the `test hook` would get http `200`, but when I push a new commit to gitbucket, the jenkins project didn't trigger a build automatically, while build by hand is ok. I am using `Gitbucket plugin` in jenkins, I already checked `Build when a change is pushed to GitBucket` option for the project, do you know what I am missing? – Eric Apr 01 '18 at 13:26
  • @NaokiTakezoe In `gogs` (a similar tool as gitbucket), the webhook is specified as `http://localhost:8282/gogs-webhook/?job=xxx`, so that it knows which jenkins job to trigger, don't know how to specify the job name in gitbucket, didn't found that information in https://plugins.jenkins.io/gitbucket – Eric Apr 01 '18 at 13:48
  • Hmm... I tested this plugin with the latest version of GitBucket and it worked fine. This plugin figures out target jobs automatically by comparing repository url in the webhook payload and job. So you have to configure a repository url in your job correctly. – Naoki Takezoe Apr 02 '18 at 02:26
  • @NaokiTakezoe About the repository url mentioned in above comment, do you mean the one in `Source Code Management` part or the one from `GitBucnet` part, I am using ssh protocol, the repository url from Source Code Management part is set as `ssh://git@localhost:29418/xxx/yyy.git`, and the url from GitBucket part is set as `http://localhost:1616/xxx/yyy`, when gitucket send a webhook for the project, the json's property `repository -> url` is `http://localhost:1616/xxx/yyy`. But still can't trigger build when push to gitbucket. Click `Build now` by hand, would succeed though. – Eric Apr 02 '18 at 06:52
  • @NaokiTakezoe I kind figured out the solution, need to use `http` instead of `ssh` to make it work, could check the answer I added below. – Eric Apr 02 '18 at 07:48

1 Answers1

3

(With the help in comment, and trying out, kind of figured out the mechanism and could built automatically via webhook now.)

Mechanism - Jenkins's Gitbucket plugin

  • The plugin determine which job to trigger by comparaing following 2 values:
    1. Jenkins job's repository url under Source Code Management.
    2. Gitbucket repo's git clone url of http protocol.

Tips:

  • So can't use ssh protocol in jenkins job's repository url under Source Code Management.
    Because it won't match the url used by gitbucket's webhook, thus can't trigger build. Use http protocol instead.

  • In jenkins's job, the url under Gitbucket section.
    It specify the home page url of the repo in gitbucket (not for git clone), it's mainly for link usage.
    It's optional, if set, then there will be a link to the url in the job's page.

Eric
  • 22,183
  • 20
  • 145
  • 196