Bitbucket integration with Jenkins

In this post, we will learn to setup Continuous Integration using Jenkins and Bitbucket. As soon as a commit happens on Bitbucket, it should trigger a Jenkins Job. To do this, we are going to create webhook on Bitbucket and supply it to a Jenkins job. This webhook will notify Jenkins about all new commits, information about the branch, commits that are made, etc.


Why this post?

We did not find a short explanation about configuring Bitbucket with Jenkins. So wanted to consolidate that information in one post.


Overview of integrating Bitbucket and Jenkins

1. Install a Jenkins plugin for Bitbucket
2. Configure your Jenkins job with Bitbucket repository details
3. Verify your Jenkins configuration looks ok
4. Configure a Webhook on Bitbucket
5. Exercise your integration
6. Check the Bitbucket Hook log


Detailed guide to integrate Jenkins and Bitbucket

1.Install and configure a Jenkins plugin for Bitbucket
This can be done under Manage JenkinsManage Plugins — Search for Bitbucket Plugin and install the same.To know more about the Bitbucket plugin,can have a look at https://wiki.jenkins.io/display/JENKINS/BitBucket+Plugin.

2. Configure your Jenkins job with Bitbucket repository details
Configure Bitbucket Repository under Source Code Management, along with credentials.

source_code_management

3. Verify your Jenkins configuration looks ok
To check whether Bitbucket Plugin got installed on Jenkins, go to JobBuild Triggers and you should be able to see option as “Build when a change is pushed to BitBucket

bitbucket_plugin

4. Configure a Webhook on Bitbucket
On Bitbucket, go to SettingsWebhookAdd Webhook.

configuring a webhook on Bibucket

Add a Webhook, as above given in the picture.The format of the URL is  http://<jenkins IP-address>/bitbucket-hook . The webhook should be active. So, click the option “active”. Under “Triggers” add “Repository Push” option and save the Webhook.

NOTE: Trailing slash should be there at the end of  URL.

5. Exercise your integration
Make a change to your code base and push it to Bitbucket. Check on Jenkins whether build gets triggered.

git

6. Check the Bitbucket Hook log
On Jenkins, when the build is triggered by Bitbucket webhook, you can check the activity under BitBucket Hook Log.

bitbucket_hook_log

In this way, we can do Bitbucket Integration with Jenkins. If you liked this article, learn more about Qxf2’s testing services for startups.


References

1. A useful 8-minute video

2. A more developer-friendly version of this post


6 thoughts on “Bitbucket integration with Jenkins

  1. Hello!
    First of all thanks for the article. I got a problem with the bitbucket webhook. I followed every step in your article. I commited and pushed to my configured git repository. It appears on bitbucket server. In the repository under Settings > Webhooks the status is ‘Never failed’ Success: x minutes ago.
    When I look into my projects Bitbucket Wehook Log on my jenkins-server there is no log. In /var/log/jenkins/jenkins.log there is also no hint on why it doesn’t work.
    Do you have an idea what’s wrong?

  2. I am following the same steps but the bitbucket web-hook returns 403 , crumbs were not sent error, and the build is not triggered.

  3. I appreciate this post. Thank you so much! One thing more though, I configured mine to trigger after a PR merge. Is there a way I can extract the destination branch and use it on the Jenkins job? Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *