Atlassian supported Jenkins integration for Bitbucket Server

SMT-2805_Bitbucket6.8_social_Twitter_600x335@2x_v02.jpg

(Update 31/Aug/2020 : We added support for using ssh credentials for cloning in version 2.1)

(Update 02/Mar/2020 : We added support for Multibranch pipeline jobs in version 1.1.0)

(Update 28/Oct/2019 : We released version 1.0 of the plugin and it is out of beta)

We’ve been building a plugin to integrate Bitbucket Server and Jenkins CI, and I’m excited to announce that it is now available. It lets you seamlessly configure a Jenkins job to clone/fetch from Bitbucket Server, removing the need for multiple plugins/apps to achieve the same workflow. To try it out you need Bitbucket Server 5.5+ and Jenkins 2.162+

We’re keen to hear your feedback, so comment with questions, feedback, and feature requests and we’ll get back to you. If you’re interested you can also contribute to our plugin. Please raise any bugs at https://issues.jenkins-ci.org with atlassian-bitbucket-server-integration-plugin as the component.

Cheers,

Imran Khan

Product Manager - Bitbucket Server

Bitbucket Server Integration with Jenkins CI - plugin features

  • supports Jenkins pipeline, Multibranch Pipeline and freestyle job type

  • provides a simple way for you to connect your Jenkins CI to Bitbucket Server instance

  • securely manage credentials inside Jenkins for cloning from Bitbucket Server

  • automatically create a webhook inside a Bitbucket repo when a Jenkins job is saved

  • select projects and repositories inside a Jenkins job through a dropdown

  • automatically send build statuses to commits and pull requests in Bitbucket Server

  • provides an option to clone from Bitbucket Smart Mirrors

  • supports both - ssh and https protocols for cloning 

Check out the short videos on how to setup and use this plugin with Jenkins pipeline and multibranch pipeline and follow the below steps:

Installing the plugin

  1. In Jenkins go to Jenkins > Manage Jenkins > Manage Plugins

  2. Click the Available tab

  3. Search for Bitbucket Server Integration

  4. Select it from the results and Click Install without restart

Adding a linked Bitbucket Server instance

image-job-config.png

After installing the plugin you need to configure at least one Bitbucket Server instance. To do this:

  1. In Jenkins go to Jenkins > Manage Jenkins > Configure System

  2. Under Bitbucket Server plugin click Add a Bitbucket instance

  3. Enter the instance details

Configuring the Jenkins job

image-global-config.png

 

  1. Go to the Source Code Management section of the Jenkins freestyle job and select Bitbucket
  2. Select the existing credentials or add new to authenticate with Bitbucket Server. The credential should be of the type Username with password
  3. Select the Bitbucket instance
  4. Enter the project key and repository slug
  5. In the Build Triggers select Bitbucket Server trigger build after push
  6. Configure rest of your build steps and save the job

When a new push happens the build will be triggered. You can then check the build info in Jenkins to see the changeset.

72 comments

Lloyd Langley August 28, 2019

Does anyone know when this is likely to be available in the Atlassian Cloud?

Regards

Lloyd

Like # people like this
Aneita
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 17, 2019

Hey @Lloyd Langley

Bitbucket Cloud can be configured to work with Jenkins today, using the Bitbucket plugin provided by Jenkins. 

I also want to share that Bitbucket Cloud has an inbuilt CI/CD tool with advanced capabilities, letting your team get all the benefits of CI without the overhead of maintaining an additional tool like Jenkins. You also won't need to worry about setting up any webhooks or configuring the two tools to work together. For more information, check out our docs

Aneita

Like # people like this
Lloyd Langley September 18, 2019

Hi @aneita,

Thnask for the notice.  it's hada 24k downloads but I haven;t found any comments on how good it is.... but don't worry.  It looks good and I hope to make use of it.

Best regards

@Lloyd Langley 

Kevin Reynolds September 30, 2019

This is great news and I am super excited to dump all the other cumbersome  plugins that I have yet to get to work.  Is there a location I can go to to ask questions and provide feedback on this implementation?  I am currently trying to get this working and am not having much success

Imran Khan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 30, 2019

Hi @Kevin Reynolds ,

You can post your feedback here or send email to ikhan at atlassian dot com. I'm keen to know what challenges you're facing. 

Kevin Reynolds October 1, 2019

Happy to post here for any others who my be facing similar. 

Environment 

BitBucket Server 6.6.2 running on Ubuntu 16.04 LTS

Jenkins 2.176.3 running in a docker container

Latest as of 9/30/2019 beta of the bitbucket addin for jenkins. 

I believe I have all the bits and pieces for the server connectivity configured fine as a connection test works fine.  

Create a webhook for when a push occurs. 

Push code to my repo but nothing happens on the jenkins side. 

If I examine the information for the hook it states a successful fire with a http status of 200

However looking at the response I see nothing in the body (not sure if there should be anything.)

A little confused as to where to go to look for potential problems as it looks like the the request was made correctly.  This should just work.  Please find attached some screen shots of the configuration.  sensitive information obfuscated. 

One thing in the jenkins log is an error with mirroring but as I understand it thats a datacenter feature not a server feature?bitbuckerServerPlugin.pngbuildTriggers.pngsourceCodeManagement.pngrequest.pngresponse.png

Sep 30, 2019 7:34:30 PM com.atlassian.bitbucket.jenkins.internal.scm.BitbucketMirrorHandler fetchRepositoriesQuietly
SEVERE: Failed to retrieve mirroring information for project DEVOPS-Docker and repo DevOps-Docker-Samples
com.atlassian.bitbucket.jenkins.internal.client.exception.BadRequestException: - response: 409

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 1, 2019

Hi @Kevin Reynolds

It appears that you've selected the wrong trigger. You need to select "Bitbucket Server trigger build after push" to get the webhook created. The one that you've selected is not related to our plugin.

Regards,
Kristy

Gaurav Joshi
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 1, 2019

Hi @Kevin Reynolds

Please enable "Bitbucket Server trigger build after push" checkbox. The other setting "Build when changes are pushed to Bitbucket" belongs to a different plugin. This setting is necessary for the webhook callback to trigger the build on this project.

Also, ignore the Mirror handler exception. We will be fixing that in the subsequent release to not throw this exception. Your configuration should work properly. This exception has no effect on your configuration. 

Also, from beta 1, you don't have to manually add webhooks to bitbucket server. The plugin does that for you provided the "Bitbucket Server trigger build after push" checkbox is enabled.

Thanks

Kevin Reynolds October 2, 2019

Awesome! Yes that was it.  thank you it now works flawlessly.   Really excited about this and happy that Atlassian dove in head first rather than the normal model of leave it up to the marketplace.  This is a core competency that should be out of the box with bitbucket.  

Is there anywhere I can see implementation information?  For example I would like to integrate the trigger into my jenkinsfile for my projects so that I can extend my config as code CI/CD model here. 

 

I looked through the snippet generator and did not see anything that jumped out at me 

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 2, 2019

Hi @Kevin Reynolds

The snippet generator should have a bbs_checkout step in there:

Screen Shot 2019-10-03 at 8.29.28 am.png

 

You should then be able to fill out all the derails and generate the snippet for your Jenkinsfile

Screen Shot 2019-10-03 at 8.30.33 am.png

 

Hope that helps,

Kristy

Aliaksei Savanchuk October 3, 2019

Hi. What is the real reason of creation of this plugins? There is a very good working one, tested with real instances/workloads.

https://github.com/jenkinsci/bitbucket-branch-source-plugin

Why do we need another one?

And if this plugin doesn't have something you need, why not just contribute to this?

Thank you.

Like # people like this
Kevin Reynolds October 3, 2019

Yes!  I discovered that yesterday, thank you.  What I am still having trouble with and maybe I am just over complicating it?  I cannot figure out how to set the trigger value for the job in the in jenkins file.  Ie  I can create a multi project pipeline and get it to fire just fine manually, in addition I can fire a freestyle job with no issue from a push as well.  The problem is once a multi project pipeline is created there is no way to change and save the configuration, So I need to be able to set the trigger value in the jenkins file. trigger.png

^^^ this guy right here.  Am I just missing something? 

 

Thank you in advance.  You guys rock!

Kevin Reynolds October 3, 2019

@Aliaksei Savanchuk Why shouldn't they?  I cant think of a better team to build the integration than the team that actually owns the application being integrated.   And besides not all teams or environments have or care to divert the resources to "just contribute to this"  I for one need a solid working solution for this.  And while I explored the tool you mention it was not working in my environment, the problem I was having got a lot of "shrugs" and I dont have time to dig into it.  This is basic functionality that should be part of the out of the box solution in the first place.   Just my humble 2cp.

Aliaksei Savanchuk October 3, 2019

@Kevin Reynolds 

I'm asking Atlassian developers here to understand their decision.

It doesn't seem smart, from my perspective, to create the same thing that already exists, making another open source out of the existing open source project, understanding that most of existing BitBucket Servers use bitbucket-branch-source. It's like if Microsoft would decide not to use Google Chromium for their new Edge but creating the other the same thing from zero.

Like Michiel Schuijer likes this
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 3, 2019

Can this plugin be configured so that it triggers when a pull request is opened? Or is it only when a developer pushes to Bitbucket?

Like # people like this
Gaurav Joshi
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 3, 2019

Hello @Mikael Sandberg, Triggering on pull request open is not available right now however we are considering adding it in a future version.

Thanks

Like # people like this
Pete Mercer October 24, 2019

@Aliaksei SavanchukThis plugin can do quite a bit more than the branch source plugin. We have used several in the marketplace to meet our developers workflows, so far this one seems to work for most teams. Hopeful we can remove all the build/webhook plugins from our instances and reduce the overhead. Also this is being worked on by Atlassian, so as customers we may have more leverage to ask for features.

Like # people like this
Imran Khan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 3, 2019

Hi everyone,

Thanks for your advocacy and feedback. On 28-Oct-2019, we released v1.0 of the plugin. We have also released a demo on Youtube to quickly guide you through the process of setting up the plugin and creating a Jenkins pipeline. 

Comment below with questions, feedback, and feature requests and we’ll get back to you. If you’re interested you can also contribute to our plugin. Please raise any bugs at https://issues.jenkins-ci.org with atlassian-bitbucket-server-integration-plugin as the component.

 

Cheers,

Imran Khan

Product Manager - Bitbucket Server

Like # people like this
Sake November 5, 2019

Great plugin! Less overhead in the current setup, a plugin in Bitbucket and Jenkins.

But we get a request if it's possible to ignore commits/pushes done by a specified user? Is this already possible and aren't we looking at the correct places to configure this or is this a feature request?

Imran Khan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 5, 2019

Hi @Sake ,

Thanks for the feedback. Can you please expand on why you want to ignore commits or pushes by a certain users - how will this help your team, when would you use it, and for this have you implemented/explored any workaround? 

Jochen Bühler November 6, 2019

Interesting plugin. Looks really nice to use and the registered webhook shows useful information.

But I am wondering why the checkout command in the Jekinsfile has to be so complicated and repeat all the information and credentials that are already configured in the job? We are currently using bitbucket-branch-source-plugin and the checkout command is just "checkout scm", where scm is injected and filled with the data from the build configuration.

The introduced duplication would keep me from using the new plugin, to be honest.

Sake November 6, 2019

@Imran Khan An explanation from some of our Jenkins users;

In Webhook to Jenkins for Bitbucket is it possible to define users from which commits should be ignored (the version we use (the free one), this is bugged).

In our current environment Jenkins gets a push request to preform some actions and starts a job. One of those actions in this job is to trigger the Maven release plugin. Maven creates a new version and afterwards does a commit to Bitbucket where all pom.xml files are edited with the increased (snapshot) version. But because there's a new commit, Bitbucket sends push request to Jenkins and job starts again and gets in a infinite loop.

They have a workaround, but it's a nasty one; abort the Jenkins job if commit is from Jenkins (the commit above). This results in a failed job, sends the information that a job failed and someone needs to check why it failed. Another annoyance are the red bars and more failed jobs which results in polluted reports.

Imran Khan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 6, 2019

Hi @Sake 

Thanks for explaining. I have created a suggestion here - https://jira.atlassian.com/browse/BSERV-12043. Please vote/watch this issue to follow the updates. 

As a workaround, can you try adding 'Excluded Users' from 'Additional Behaviours' without any other changes to your config? Hope this helps. image.png

 

 

Cheers,

Imran

Sake November 7, 2019

@Imran Khan Thanks for creating the item, it would be a good addition to Bitbucket! The workaround might look like what our users want in the meantime, thank you! Maybe document it?

gafnerpa November 12, 2019

Looks like a very good possibility to work with the CI/CD capablities of Jenkins (pipeline as code).

I really like the overall integration between JIRA, Bitbucket Server and Bamboo (creating an issue creates a new branch, pull request requires a successful build etc) but I miss the pipeline in Bamboo compared to Jenkins.

Is there already a possiblity to use the power of JIRA and Bitbucket Server together with Jenkins or are there plans to support it?

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events