0

We have a Jenkins and we have a local Bitbucket Server.

We already installed

  • "Bitbucket Plugin" on Jenkins
  • "Post Webhooks" on Bitbucket

Then we set in jenkins

  • Branches to build
    • Branch Specifier to "**"

In Post Webhooks we checked all events.

Now when we push a branch or delete a Pull request, jenkins is triggered and seems to build every branch which has new commits. (But somehow it is not triggered when we create a pull request.)

The question is now: How do we get our test results to Bitbucket to block a merge when a test failes?

We found the Plugin "Violations to Bitbucket Server" but it only covers results of static code analysis and no jUnit or surfire reports.

The whole thing feels sketchy... Is there any good tutorial which tells how to integrate jenkins and bitbucket in both directions? Or is it not possible with available plugins?

2

There are three pieces here:

  • How do you trigger a build on PR creation? For this, I used the "pull request notifier for bitbucket" plugin. Technically, you don't need this if you use the "Bitbucket Branch Source" plugin (mentioned below), but it does provide a nice quality-of-life improvement for self-hosted Bitbucket Server users.

  • How does Bitbucket know when a Jenkins build has failed? There are a few different options here. In my opinion, by far the best way to solve this issue is with the CloudBees-official "Bitbucket Branch Source" plugin. This plugin takes care of every aspect of setup that you need on the Jenkins end of things (if you use Bitbucket Cloud, it can even take care of configuration on the Bitbucket end too). Among other things, this plugin auto-discovers repositories, branches, and pull requests. It also reports test results back to Bitbucket. If you don't want to use this plugin for whatever reason, there are some other solutions that have worked for me as well, in particular the "Stash notifier" plugin. This plugin just reports test results back to Bitbucket, nothing more.

  • How do you prevent failing PRs from being merged? This can be addressed with repository settings in Bitbucket. Specifically, Repository Settings > Merge Checks > Minimum successful builds. If you want to apply this to all of the repos in a project instead of just one repo at a time, this setting can also be adjusted on a project level with recent versions of Bitbucket (since 5.5, IIRC - I'm too lazy to look up changelogs right now).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.