It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Atlassian supported Jenkins integration for Bitbucket Server

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

(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 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 

If you’re ready to take it for a spin just watch the short video on Youtube 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.

33 comments

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

Regards

Lloyd

Like Christopher Van Kemseke likes this
aneita Atlassian Team Sep 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

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 

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 Sep 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. 

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 Oct 01, 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 Oct 01, 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

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 Oct 02, 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

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 Michiel Schuijer likes this

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!

@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.

@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 Oct 03, 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 Javi Rodríguez likes this
Gaurav Joshi Atlassian Team Oct 03, 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

@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 Nov 03, 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

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 Nov 05, 2019

Hi @Sake Paulusma ,

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? 

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.

@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.

Hi @Sake Paulusma 

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

@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?

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
Community showcase
Posted in Bitbucket

Share your software development horror stories!

Hey Community! I work on the Bitbucket product marketing team. With Halloween approaching, we wanted to discuss a topic tailor-made for October: development horror stories. Whether it was a lurk...

1,511 views 11 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you