How can I get Jenkins builds to report failures back to Bitbucket server?

While the Webhook to Jenkins for Bitbucket can help notify Jenkins to poll whenever there is a commit, you still need to be mindful of the “lazy ref updates” in Bitbucket (described in this thread)

We had to implement something that would do a get to the REST API for the pull-request/*/changes before the call to the Jenkins /git/notifyCommit url.

The last Jenkins URL /git/notifyCommit comes from the Jenkins Git plugin.

See more at "Configuring Webhook To Jenkins for Bitbucket".

Once Jenkins is properly called, you can then, as mentioned in "Notify build status from Jenkins to Bitbucket Server", use the "Jenkins Stash Pullrequest Builder", from nemccarthy/stash-pullrequest-builder-plugin.

http://blog.nemccarthy.me/wp-content/uploads/2015/03/Screen-Shot-2015-03-23-at-11.08.56-am.png


The bitbucket server has build-status API. It stores a build-status for particular commit, there is no separate PR build status. The PR build status is a build status of the head commit in this PR.

You can implement yourself the rest api call to update the build status or to use one of the existing plugins. We use Post Webhooks for Bitbucket bitbucket plugin in conjunction with Bitbucket Branch Source jenkins plugin.