3

We have configured Jenkins multibranch pipelines to automatically build feature branches that are filed as Pull request in Bitbucket. For the Webhook creatin in Bitbucket(Server), we use Parametrized Builds for Jenkins. In Jenkins we have successfully configured this, the buildable branches are detected like a charm.

The thing is that I have to tell Jenkins to check for new branches every 2 Minutes, I'd rather have Jenkins notified when a PR is created,merged or changed. All other notifications from Bitbucket work pretty well, changes in a multibranch build lead to an automatic build, normal builds on none multibranch pipelines also work.

Does sombody know why the scan cannot be triggered from Bitbucket? I can provide Screenshots of my configuration if someone needs that... Thanks Carsten

Carsten Hilber
  • 246
  • 1
  • 3
  • 13

1 Answers1

1

You'd need to add a corresponding Webhook to each repository in Bitbucket to have builds being triggered on specific actions. We are using an extra add-on in Bitbucket (https://marketplace.atlassian.com/apps/1215474/post-webhooks-for-bitbucket?hosting=server&tab=overview) but you could even use the default Webhook implementation in Bitbucket (described here https://confluence.atlassian.com/bitbucketserver/managing-webhooks-in-bitbucket-server-938025878.html)

The endpoint in Jenkins is defined by the Multibranch plugin. It is this one: "YOUR_JENKINS_URL/bitbucket-scmsource-hook/notify"

See https://support.cloudbees.com/hc/en-us/articles/115000053051-How-to-Trigger-Multibranch-Jobs-from-BitBucket-Server- for a good guide.

krulls
  • 26
  • 2
  • Hi krulls, thanks for your answer. I should have give more information on the webhooks, sorry for that. We use Parametrized Builds for Jenkins to define the Web Hooks. It works fine with all other Cases we notify Jenkins. Nevertheless, it does not work on multibranch pipelines. I think it is more a bug on the Jenkins side, because I can see that Bitbucket notifies Jenkins, so the REST call is made and it succeeds with 200. – Carsten Hilber Mar 02 '21 at 09:03
  • would rather like to write to you in person but cannot find a way here in the UI. I think that it could also be a configuration issue in the multibranch job. if you could add a screenshot of the configuration it would help. – krulls Mar 03 '21 at 11:43
  • next to that I don't get what you mean exactly with "use Parametrized Builds for Jenkins to define the Web Hooks". the web hook itself is provided by the multibranch plugin I think, you cannot change its setting. and then you just use the webhook by configuring it in the Bitbucket repository. what else do you configure on the Jenkins job side? as soon as you create a multlibranch job that points to the repository, the webhook implementation will delegate any news (REST requests) to this job. – krulls Mar 03 '21 at 11:47
  • "Parametrized Builds for Jenkins" is a Bitbucket Plug-In that eases the management of WebHooks. This way it is easier for us, because we have a lot of hooks. The thing is, everything works fine, the only thing that does not is that the scan of the multibranch pipeline does not work. – Carsten Hilber Mar 09 '21 at 15:15
  • I found an open issue on that plug-In seems that its just a bug though... https://github.com/ParameterizedBuilds/parameterized-builds/issues/232 – Carsten Hilber Mar 09 '21 at 15:16
  • Ok, nevertheless, it should work as you initially wrote. Even when we don't have the Plug-In for Bitbucket, the docs of bitbucket-source-plugin will register an endpoint and this is configured as well. So I followed the docs and brought BB to fire the hook. Jekins is ignoring it and is still not starting the scan, even it is notified. I turned on (Jenkins) logging as they mentioned in faq, but there is nothing but on entry: com.cloudbees.jenkins.plugins.bitbucket.hooks.BitbucketSCMSourcePushHookReceiver doNotify server_url request parameter found. Bitbucket Native Server webhook incoming. – Carsten Hilber Mar 09 '21 at 16:20
  • interesting plugin, did not hear of it before. seems to be a rather complex set up compared to the default approach to let Bitbucket just "fire" the webhook and let do Jenkins do its own magic. can't help you with that, sorry. Can remember an issue lately when we upgraded Bitbucket Server to newest LTS version, the BitBucket Branch Source Plugin (in Jenkins) required a new setting "Call Changes api" to keep triggering PR jobs. But that might not be your issue. – krulls Mar 11 '21 at 06:39