How to integrate Bitbucket Server with Jenkins Pipelines

We want to automate project build using a Parametrised Jenkins Pipeline of the source code stored in Bitbucket Server.
December 16, 2020
Productivity
Use-Case
Technology

Objective

We want to automate project build using a Parametrised Jenkins Pipeline of the source code stored in Bitbucket Server.

Jenkins Setup

Firstly, we need to install the necessary Jenkins plugins.

Git Parameter - https://plugins.jenkins.io/git-parameter/ - adds git parameters to the Jenkins pipelines, you can use it to specify the branch to check in or any other things used in the Jenkins pipeline.

Build Authorization Token Root Plugin - https://plugins.jenkins.io/build-token-root/ - allows to use the build token for external builds.

Secondly, create a Jenkins Pipeline that checks out and builds the code.

Afterwards, add branch as a parameter.

Jenkins Bitbucket integration setup step 1

Generate an authentication token and make sure you don’t share it.

Jenkins Bitbucket integration setup step 2

Add create your super simple pipeline that builds the branch or just print the hello world message.

Jenkins Bitbucket integration setup step 3

Now we are ready for the Bitbucket Server configuration.

Bitbucket Setup

Install the Bitbucket Post Webhooks plugin and navigate to the repository settings to configure the triggers.

The url should be in the following format and parameters are passed in the url.

http://jenkins.mwf-test.com:8080/buildByToken/buildWithParameters?token=super-secret-access-token-123&job=Pipeline-01&Branch=master

Jenkins Bitbucket integration setup in Bitbucket Server step 1

Click the test connection to see if it triggers the message.

Jenkins Bitbucket integration setup in Bitbucket Server step 2

Select the triggers for the notifications., For instance, it makes sense to sell “On push“.

Push the code to your master branch and trigger the build!

View of triggered builds in Jenkins
View of triggered Jenkins pipelines

Enjoy the building and welcome to our world!

Products we’re proud of

Articles you might like

Unlock Microsoft Teams
December 16, 2020
Unlock Microsoft Teams
You can unlock Microsoft Teams by integrating it with tools your team uses.For Software development teams it can be Jira, Confluence, Bitbucket and Bamboo.For HR teams Workday and other HR systems.For Sales teams it can be CRM integration.
Read more >
Bring information from GitHub into Confluence
December 16, 2020
Bring information from GitHub into Confluence
Integrate GitHub with Confluence to increase team velocity and transparency. Enrich information about pull requests, read me and other files, issues and repositories. Know the state of those items without leaving Confluence.
Read more >
Atlassian tool help enterprises accelerate DevOps adoption
December 16, 2020
Atlassian tool help enterprises accelerate DevOps adoption
Atlassian connects development, IT operations, and agile teams with automation that spans our products and third-party tools. Your team can bring the tools they want, select from our tools, or use a mix of both.
Read more >

New blog posts

AWS vs Azure vs Google Cloud - Which Cloud Services is better for Enterprises?
July 17, 2021
AWS vs Azure vs Google Cloud - Which Cloud Services is better for Enterprises?
When selecting a cloud platform for your enterprise or organisation, it's almost as if you have an infinite amount of choices. Each service provider has its own set of benefits and features that make them stand out from the crowd, but there is no one best choice without considering all aspects such as budget constraints, available services, etc. Do some research on what type of services will suit your enterprise or organisation best, then decide based on this information.
Read more >
GitHub and GitLab Jira integration for Jira Data Center
July 8, 2021
GitHub and GitLab Jira integration for Jira Data Center
In this post, you can learn about Jira Data Center performance testing of GitHub and GitLab Jira integration App.
Read more >
Old Microsoft Teams Incoming Webhook urls stopped working on the 1st of July 2021
July 3, 2021
Old Microsoft Teams Incoming Webhook urls stopped working on the 1st of July 2021
If you used the Incoming Webhook urls generated before February 2021 you should have updated them before the 1st of July 2021 PST or they won't work anymore. You should see a message there "You must update this connection to keep using it after June 30, 2021. ".
Read more >