Skip to content

Integration with Bitbucket

To integrate Jenkins with Bitbucket, follow these steps.

From the Bitbucket project, click on your user icon and select “Manage account”:

Select “HTTP access token” in the menu on the left. Then click "Create token":

Add a token name. Set the Permissions to “Repository read”. Click “Create”:

Note: see below if using Jenkins to setup the webhook for additional options

Make sure to copy the generated token as you will not be able view this again.

Create new project in Jenkins. Enter name of project. Select multibranch pipeline:

Add source - select Bitbucket:

Add Credential - select project name:

Change “Kind” to “Username with password”. Paste the HTTP access token created from Bitbucket. Give unique ID:

Select new Credential. Set the “Owner” to the Bitbucket project key (4 letter identifier). Once the Owner is entered, the Repository Name should show up in list:

Then Add “Advanced clone behaviors”, and ensure that “Fetch tags” is checked:

After saving, the repositories will be scanned:

To automatically start a build when a commit is pushed to the repository you have 2 options.

Allow Jenkins to automatically setup the webhook on Bitbucket

When creating the access token in Bitbucket give the permission

Then configure your project in Jenkins

  • Add the option "Override hook management" to the repository settings

  • Select the "Use item credentials for hook management" option

  • Once saved Jenkins will automatically add the required webhook to the Bitbucket repository

To manually setup the webhook in Bitbucket

  • First goto the settings on the Bitbucket project

  • Goto the webhooks section

  • Give your new webhook a name and change the url to http://<jenkins_url>:8080/bitbucket-scmsource-hook/notify?server_url=https%3A%2F%2F<bitbucket_url>
  • Select the following options for the webhook

  • And then save the webhook