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 Jenkins — Manage 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.
3. Verify your Jenkins configuration looks ok
To check whether Bitbucket Plugin got installed on Jenkins, go to Job—Build Triggers and you should be able to see option as “Build when a change is pushed to BitBucket”
4. Configure a Webhook on Bitbucket
On Bitbucket, go to Settings — Webhook — Add Webhook.
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.
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.
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
2. A more developer-friendly version of this post
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 .
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?
Hi,
Did you set Build trigger on Jenkins? to build every time a change is pushed?
I am following the same steps but the bitbucket web-hook returns 403 , crumbs were not sent error, and the build is not triggered.
Hi,
I suspect it to be more an access issue between Jenkins and Bitbucket servers. Can you check if the proxy settings are allowing this access?
Also, you may want to refer this link which I found on net https://stackoverflow.com/questions/44711696/spinnaker-403-no-valid-crumb-was-included-in-the-request
Let me know if you need further assistance. Share screenshot of the errors, if possible next time.
Thanks & Regards,
Rohini
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!
Hi Rowe,
I hope you can find a solution for your question in this link:
https://medium.com/@austin.johnson/triggering-jenkins-from-a-push-to-a-specific-branch-bitbucket-6effecb4b451
Thank you.