There is a great plugin out there that helps connecting Jenkins to your Bitbucket account called Bitbucket Branch Source Plugin.
This plugin comes really handy especially if your project has multiple branches. In Jenkins lingo “Multibranch Project”.
Let’s go over the plugin installation and configuration:
- Go to “Manage Jenkins” 👉 “Manage Plugins” then search and install the following:
- Once installed, you should see the following option when creating a new Jenkins project:
- Select it and give your project a name.
- The project settings screen will open:
You’ll need to configure a username/password credentials in Jenkins (beforehand) which will allow the plugin to scan for Bitbucket repositories.
The “Owner” field should be filled with your Bitbucket project ID. I was able to find it by clicking on my Bitbucket profile and then on “Teams”
Now check your browser URL to get your account ID:
As for the “Behaviors” section, we find “Discover pull requests from origin” and “Merging the pull request with the current target branch revision” to work best for our multibranch use case. By using this method combined with Bitbucket “Merge Checks”
We assure that any pull requests are built and merged locally (on one of Jenkins slaves) with the master branch before allowing it to merge on the remote repo.
And now for a small but very annoying Gotcha…
In case you’ve got a project in Jenkins named “MY/PROJECT” (notice the slash). You may have encountered an issue where links like:
In order to fix that all you have to do is add the following to your catalina.properties file (if using Bitnami Jenkins it should be under /opt/bitnami/apache-tomcat/conf/catalina.properties):
# Custom modification - This should fix blueocean broken links
Now restart Apache and you should be good to go.
Hope this helps.