How to Trigger Multibranch Jobs from BitBucket Server

Issue

  • I want to configure Jenkins and BitBucket Cloud to automatically trigger Multibranch or Bitbcuket Team/Project jobs on changes

Environment

Resolution

The BitBucket Branch Source plugin provide support for integration of Bitbucket with multibranch project such as Pipeline Multibranch. The API listens for notification to the endpoint /bitbucket-scmsource-hook/notify.

Configuration in Jenkins

Multibranch Project

To track a single repository, create an item of type Multibranch Pipeline and use the BitBucket branch source:

Configure the SCM as explained in the documentation of the Bitbucket Branch Source Plugin. In the Advanced section, specify the Bitbucket server URL - as well as the SSH port if using SSH authentication for checkout credentials:

Bitbucket Team/Project

To track multiple repositories of a Bitbucket project, create an item of type BitBucket Team/Project and use BitBucket Team/Project repository source:

Configure the SCM as explained in the documentation of the Bitbucket Branch Source Plugin. In the Advanced section, specify the Bitbucket server URL - as well as the SSH port if using SSH authentication for checkout credentials:

Once a project is saved, it automatically listens for events on the /bitbucket-scmsource-hook/notify.

Further Configuration

Since Bitbucket Branch Source 2.1.1 and Post Webhooks for Bitbucket 1.4.1 (bitbucket add-on), you can enable the option Auto-register webhook to let Jenkins automatically register a webhook for your repository/ies. This is the recommended, quicker, easiest configuration.

Note: For previous versions, the only workaround is to configure each repository hook manually in Bitbucket Server. But you can use the Bitbucket REST API to help you with that process, have a look at the article Generate webhooks in BitBucket Server via REST API for Pipeline Multibranch

Configuration in Bitbucket Server

You need to install the add-on Post Webhooks for Bitbucket. This add-on has been designed by the community to provide support to the Bitbucket Branch Source plugin with BitBucket Server as part of JENKINS-33507. The source code of this add-on can be found on GitHub at https://github.com/topicusfinan/bitbucket-webhooks-plugin.

Once installed, this add-on adds a Webhooks section in the Settings of you repositories. To create a Webhook for a repository, click on Add WebHook on the top right:

Give it the name you want and specify the Bitbucket Branch Source endpoint $JENKINS_URL/bitbucket-scmsource-hook/notify:

Ensure that the webhook is created and enabled:

From now on, Push and Pull Request events from that repository are notified to the Bitbucket Branch Source plugin.

Troubleshooting

Please have a look at Bitbucket Webhooks Troubleshooting to troubleshoot issues with these solutions.

References

Bitbucket Integration

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.