alcide

Alcide Blog

Cloud-native Security Provider

How to Configure Jenkins BitBucket Branch Source Plugin + One Very Annoying Gotcha..

Jul 24, 2018 4:58:42 AM / by Elad Ishay

In case your Git repo resides in Bitbucket and Jenkins is your favourite butler, you’ve come to the right place.

Source: https://jenkins.io/artwork/

 

 

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:

 
In our case the ID is alcideio

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:

https://YOUR_JENKINS_SERVER/jenkins/blue/organizations/jenkins/MY%2FPROJECT/detail/PR-1460/13/pipeline

are broken when accessed directly via the old Jenkins UI.
Here at alcide.io, we have seen this happening while using BlueOcean combined with Apache-Tomcat and Bitbucket Branch Source Plugin.

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
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true

Now restart Apache and you should be good to go.
Hope this helps.

Topics: devsecops, Jenkins, BlueOcean, Apache-Tomcat, Bitbucket, bitnami