If you use Bitbucket Server to host your code and Jenkins to run your tests, you have to link both systems. I.e., once you push changes to Bitbucket, you want Jenkins to start a new build automatically.

For some reason, there are lots of different solutions for this task, but most of them are outdated or quite complicated. I’ll give a short overview about the different ways I’ve tried and show a really easy solution at the end.

Official solution (Bitbucket Server 6.8+)

On the release notes for Bitbucket Server 6.8, Atlassian links to a Jenkins plugin.

  • The wiki page marks it as “beta”
  • You have to create a (Bitbucket) personal access token with Admin rights for everything - unclear why this is needed
  • You have to create an “auth credential”, unclear what this means
  • During a quick test, I couldn’t make it work

Jenkins plugin ‘Bitbucket’

Lots of blog posts mention this plugin, it looks like it has been the common solution for a while. However, it’s unmaintained now.

  • Unmaintained
  • Another plugin needed on Bitbucket side
  • A Github issue mentions it would work with standard Webhooks; however it’s unclear to me how to do it
  • No documentation how to use it

Jenkins plugin ‘Bitbucket Branch Source’

This plugin is also mentioned sometimes. I haven’t tried it.

Easiest solution (no plugins needed)

Luckily, there’s no particular Bitbucket plugin needed at all. All we need is Jenkins’ basic Git plugin, but most probably, you have this already.

Using ‘polling’ would already work. There would be some delay between pushing and building - depending on your use case, this can be acceptable or not.

Additionally, the Git plugin supports a simple GET request to trigger a poll immediately:

$ curl -i "http://my.jenkins.url/git/notifyCommit?url=ssh://[email protected]:7999/myproject/myapp.git"

In Bitbucket, just create a new Webhook with a url like the one above, and you are done.