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.