This is the configuration guide for people who use the Git Plugin in Jenkins. If you use the Bitbucket Branch Source 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 Jenkins

  1. Install the Git Plugin in Jenkins.
  2. Configure your project to use Git for your Source Code Management. You will need to keep the Repository URL you use for configuration in Bitbucket.
  3. Enable the Poll SCM option in the Build Triggers. This is required to remotely trigger a build. Since we don’t really need to poll, you can set the poll frequency to poll very infrequently.
  4. Save your project configuration.

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. 

    Versions of Bitbucket prior to 5.2.0 will not have a dropdown, and instead will just have a toggle.

    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. Make sure you select the Git Plugin as the Jenkins endpoint.
  7. 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!


Notifying Bitbucket of Jenkins Build Result

Once the build has been completed, it’d be nice to let Stash know the results of the build. By installing the Jenkins Stash Notifier Plugin, it’s a piece of cake.

  1. Install the Stash Notifier Plugin in Jenkins.
  2. In Jenkins, go to your project’s configuration.
  3. At the bottom, add a “Post-build action” of “Notify Stash Instance.”
  4. Enter your Stash URL, username, and password.
  5. That’s it!

What it looks like

On the commit page, it shows the Build Result (in this case a pass) in the far-right column


Clicking the result displays a popup containing all builds associated with the commit. You can click on the title to go directly to the Jenkins page for that build.