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


Nilaya Indurkar

I have started my career with Networking Domain.Have 8 years of relevant IT experience in network protocol testing.Experienced in functional testing of various networking protocols and Device-specific features.I was involved mainly in Manual Testing, Writing Test Plans, Updating Release Notes, Documentation for the same.Mainly worked on L4-L7 Load Balancers, Application Accelerators, Application Delivery Controllers.After that, I was looking for Automation Testing and Remote Work Opportunities.I found Qxf2 is the right place.Learning Python,Automation Framework, Exploring New Tools for Automation.My hobbies are listening classical,non-classical music .

2 Comments

  1. racoon said:

    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?

    November 9, 2018
    Reply
    • Shivahari P Shivahari P said:

      Hi,
      Did you set Build trigger on Jenkins? to build every time a change is pushed?

      November 13, 2018
      Reply

Leave a Reply

Your email address will not be published.