Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Pull request merge triggers build 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 Leader Dec 10, 2019

Hi @Kamil_Aliev,

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.

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 Leader Dec 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.

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?

@Kamil_Aliev

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

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
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,826 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you