Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

My work is running Jenkins and Bitbucket Server (so instead of the bitbucket cloud, they host their own bitbucket version). I am used to having passing/failing builds on github and bitbucket cloud immediately reporting back on PRs and branches as to whether the build passed or failed. I want to give that gift to my team in the current environment. How do I get PRs in Bitbucket server to receive success/failure of builds from Jenkins?


[Figure 1 just shows an example of the functionality I want, operational on PRs in github+codeship]


PR with build success and failures on github and codeship

like image 997
Kzqai Avatar asked Mar 21 '18 14:03

Kzqai


2 Answers

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

like image 161
VonC Avatar answered Oct 20 '22 17:10

VonC


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.

like image 28
Yuri G. Avatar answered Oct 20 '22 18:10

Yuri G.