Table of Contents
Integrate BitBucket webhook with Jenkins to auto build on push of code to a bitbucket repository
In this tutorial, we will
- Add Jenkins add-on/plugin to BitBucket server
- Install BitBucket Plugin in Jenkins
- Configure Jenkins
- Configure BitBucket
Add Jenkins add on to BitBucket server
Once you have installed BitBucket server on your machine, make sure that it is working. The default port is 7990, so you should be able to access it by using localhost: 7990.
- Click on Settings and on the left side under ADD-ONS, click on Find new add-ons.
- Search Jenkins and add the plugin
Install BitBucket Plugin in Jenkins
- Make sure Jenkins is up and Running, in my case, it is running on localhost: 8080
- In Jenkins go to Jenkins->Plugin Manager and install BitBucket Plugin and then restart Jenkins.
Configure Jenkins
- Now go the Job, which you have created and under Source Code Management Plugin, give the GIT Clone URL as shown below in the screenshot.
- Under Build, Triggers make sure two boxes are checked
a. Build when a change is published to BitBucket
b. Poll SCM
Configure BitBucket
- Now go to BitBucket -> Repositories and select the repo for which are Jenkins has been configured
- Click on the setting (icon on the left-hand side) and then hooks. Edit the Bitbucket Server Webhook to Jenkins
- a. Enter your Jenkins URL
- b. Repo Clone URL: Select the URL and the same protocol which BitBucket is providing you to clone. In case username is missing from the URL, we need to add it manually.I had to use Chrome Developer tools and remove the disabled flag from the input box and then add username manually.
Ignore above step if the username is in URL- c. Once it is enabled edit the URL with http://UserName@Server/gitrepo
- Click on Trigger Jenkins if it says successful everything is fine.
- Commit some code and Jenkins should automatically start the build. Refresh the Jenkins page is auto refresh is disabled