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

4

14

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

Hexastich answered 21/3, 2018 at 14:44 Comment(1)
Hmm, enable Bitbucket Server Webhook to Jenkins on bitbucket, create a job on jenkins, probably using Stash Pull Request Builder Plugin. Our company has that working for jenkins & bitbucked and there is nothing difficult in the implementation.Abbate
A
5

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.

https://static.mcmap.net/file/mcmap/ZG-Ab5ovKRIsaRbQamytWRMhbn-odS2tX3/wp-content/uploads/2015/03/Screen-Shot-2015-03-23-at-11.08.56-am.png

Algoid answered 24/3, 2018 at 19:29 Comment(0)
L
2

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.

Linc answered 26/3, 2018 at 18:53 Comment(0)
A
2

You could you use BitBucket REST API to achieve this ?

Here the how-to update commits with the build status : Updating build status for commits

Commit status are then shown in Pull Request and on branches

Antonietta answered 27/3, 2018 at 14:45 Comment(0)
W
1

you can setup Stash notifier plugin , it workds perfectly with BitBucket and notifies build status to branch and pull request

Winshell answered 26/3, 2018 at 19:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.