This is the configuration guide for people who use Jenkins Blue Ocean. If you're using just the Bitbucket Branch Source plugin see here. If you're using the Git Plugin, see here.

If you have not already downloaded the plugin, you can get it here

Using Git’s post-receive hooks, it’s possible to trigger builds on Jenkins after a commit. There is a little configuration required in both Jenkins and Bitbucket.

Configuring your Jenkins Job

You can use either the Multibranch Pipeline job or the Bitbucket Team job with the plugin. Both configurations are very similar. Here's an example:

  1. Navigate to Jenkins Blue Ocean. Click the New Pipeline button on the right.

  2. Select Bitbucket Server from the CI choices.

  3. If you've not yet added a Bitbucket Server, go ahead and do that by clicking the Add button.

  4. Pick your project, your repository and you're done! Jenkins will now start indexing the repository.

Configuring Bitbucket

Configuring on a per-Repository Basis

  1. In Bitbucket, install Webhook to Jenkins for Bitbucket.

  2. Navigate to your repository and hit the Repository Settings tab. 

  3. In the left-side navigation, click the Hooks link. 

  4. Select Enabled from the dropdown for the Post-Receive hook, Bitbucket Server Webhook to Jenkins
    (info) Versions of Bitbucket prior to 5.2.0 will not have a dropdown, and instead will just have a toggle.
    (info) If you're using Bitbucket 5.2.0+ and you've already setup a project configuration that you would like to use, you can select Inherited and stop here.


  5. Enter the URL for your Jenkins instance and the Repository URL that you configured Jenkins to use. You can use the dropdown to get the clone URL for each supported protocol. Afterwards, feel free to change it to match your Jenkins instance. 

  6. Click the Trigger Jenkins button to test your configuration. If it worked, it’d look like this: 

That’s it!

With both Jenkins and Bitbucket now configured, if you commit code, a build trigger will automatically occur. What happens is the post-receive hook fires a GET request to Jenkins, which then tells it to poll the repository (why you need to have polling turned on). The poll checks to see if there are actually any changes. Since there are, it triggers the build!

Configuring on a per-Project Basis

  1. In Bitbucket, install Webhook to Jenkins for Bitbucket.

  2. Navigate to your project and hit the Project Settings tab. 

  3. In the left-side navigation, click the Hooks link. 

  4. Toggle the Post-Receive hook, Bitbucket Server Webhook to Jenkins to Enabled.

  5. Enter the URL for your Jenkins instance and the Repository URL that you configured Jenkins to use. You can use the dropdown to get the clone URL for each supported protocol. Afterwards, feel free to change it to match your Jenkins instance. Make sure you include the {repository} field so Jenkins knows where to add repository id for the URL.

  6. Click the Trigger Jenkins button to test your configuration. If it worked, it’d look like this: 

That’s it!

With both Jenkins and Bitbucket now configured, if you commit code, a build trigger will automatically occur. What happens is the post-receive hook fires a GET request to Jenkins, which then tells it to poll the repository (why you need to have polling turned on). The poll checks to see if there are actually any changes. Since there are, it triggers the build!