Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Pull request merge triggers build

Deleted user December 10, 2019 edited

Hello, Atlassian community!

I'm trying to add a successful build restriction for merging pull request. If I get it right, the idea is when one presses merge button (which is clickable after reviewers have approved it) that action triggers, for example, jenkins job and if it is successful, performs the merge, otherwise tells you it wasn't performed due to build failure.

My current setup (integration) with jenkins involves web-hooks to triggers jobs, I'm aware about event payloads and stuff, but cant find anything related to the example I provided above - does it work on the same principle? where do I specify what job to trigger? For example, I couldnt find any relevant event for that over here  - https://confluence.atlassian.com/bitbucketserver0514/using-bitbucket-server/managing-webhooks-in-bitbucket-server/event-payload?utm_campaign=in-app-help&utm_medium=in-app-help&utm_source=stash#Eventpayload-repositoryevents. Merged event looks like the one that happens on completed merge, which is not what Im looking for.

Looking for more detailed explanation/guide.

2 answers

1 accepted

0 votes
Answer accepted
Mikael Sandberg
Community Champion
December 10, 2019

Hi @[deleted],

You cannot kick off a build when clicking the merge button and use the built-in check that only allows merging a pull request if there are minimum successful builds, that check happens before the merge button is enabled. The way I have it set up in my Bitbucket environment is to use a free app called Pull request notifier for Bitbucket. It used to be listed on the Marketplace, but the developer pulled it after Bitbucket 6.0 release but has now updated the app so it works with Bitbucket 6.x. The app sends a webhook to Jenkins based on your configuration, and then on Jenkins we use Bitbucket Notifier Plugin to let Bitbucket know of the build result.

You may also want to take a look at the Atlassian supported Jenkins integration that was just released. It does not allow you to control when the webhook is triggered, but if you want to build on every commit, I would use this one.

Deleted user December 10, 2019

Thank you, @Mikael Sandberg, for your reply. I think I'll consider builds on every commit, through webhooks though, as I realized our company jenkins environment doesn't have bitbucket plugin that you mentioned. And you know it may take time to be added...

I want to ask you one more question - I've seen there is an event, called "Approved", which is triggered when one of the reviewers approves the pull request. I think I could use this one to reduce the number of unncessary builds. Of course I'm going to test it, just interested in your thoughts.

Thanks again for quick reply!

Mikael Sandberg
Community Champion
December 11, 2019

If you use the minimum successful build check then triggering the build on the Approved event should be fine if you want to avoid a lot of extra builds. In that case, I would also enable Auto-unapprove if you have not done that already.

Deleted user December 12, 2019

Also found something called "External Merge Check Hook" in Pull requests -> Merge checks section. I realized its an Add-on, but since I'm not Bitbacket admin in our environment, I happen to find things on the way xD

More info - https://external-hooks.reconquest.io/

Do you have any experience using this one?

Stanislav Seletskiy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 12, 2019 edited

@[deleted]

Hey, I'm one of the External Hooks add-on maintainers.

You can use External Merge Check hook to veto pull request merge using arbitrary executable (e.g. shell script).

How it works:

  • user visits pull request page
  • script which is configured in External Merge Check is executed
  • if script exits with non-zero status code, then the merge button is disabled and any output from script becomes available via tooltip on the merge button

Feel free to reach us directly if you need more help: we@reconquest.io

0 votes
Deleted user December 10, 2019

My best guess is to triggers jobs on every commit and mark them successful/failed using REST API https://developer.atlassian.com/server/bitbucket/how-tos/updating-build-status-for-commits/

Please confirm if that's how it is done.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events