Merge a PR on a conditional check
Asked by Raktim:

Hello Team,

We'd need to know how we can put a condition with a PR while merging this to the main branch ; so for some PRs I have 2 successful build required but for some of them I need only one green build ; How can I achieve that flexibility?

Thanks,

R..


Answers:
author: Patrik S
body: Hello [@Raktim](/t5/user/viewprofilepage/user-id/4905030) ,

Welcome to Atlassian Community!

You can configure the merge checks by setting up Branch permissions in your repository, where , among other possible checks, you can define the number of successful builds required before merging to a given branch/branch pattern.

You can get more details about branch permissions in the following documentation:

* <https://confluence.atlassian.com/bitbucketserver050/using-branch-permissions-913474668.html>

However, since the merge checks in the branch permissions are configured from the pull request's destination branch perspective, and you mentioned your pull request are both merging to main branch, I'm afraid it would not be possible to configure two different rules for main branch, one requiring 1 successful build and the other 2 successful build, as Bitbucket would not be able to know when to apply one rule or another.

The only way current way to achieve different number of required successful builds would be if you were merging to different branches, so you could have one branch permissions setup for each of the destination branches.

Hope that helps to clarify your questions.

Thank you, [@Raktim](/t5/user/viewprofilepage/user-id/4905030) .

Kind regards,

Patrik S

comments: author: Ulrich Kuhnhardt _IzymesCo_
body: Thanks for clarifying [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) - I understand that [@Raktim](/t5/user/viewprofilepage/user-id/4905030) may have 2 different _source_ branches both merging to main branch. Say we have PRs from bugfix/abc to main require 1 successful build and PRs from feature/xyz require 2 successful builds.

Can you confirm, [@Raktim](/t5/user/viewprofilepage/user-id/4905030)

If that's the use case - [Workzone for BB Cloud](https://marketplace.atlassian.com/apps/1211303/workzone-pullrequest-workflow?hosting=cloud&tab=overview) is an app you can use to define such conditions.

![workzone successful builds.png](https://community.atlassian.com/t5/image/serverpage/image-id/195732i872BAF67C76E1FF0/image-size/large?v=v2&px=999 "workzone successful builds.png")

The screenshot doesn't exactly show the number of required builds, but the configs have 2 and 1 required build respectively.

Disclaimer: Izymes just released Workzone Cloud (free) to the MP - let me know if you need any help setting it up.


author: Raktim
body: Hey [@Ulrich Kuhnhardt _IzymesCo_](/t5/user/viewprofilepage/user-id/4011392)

yes that was exactly what I wanted ; but let's say we want to configure that so that it works every time . How do I tell BB if for PR 1 is different from Pr 2 ? So I need to use some commit message or branch names ?


author: Ulrich Kuhnhardt _IzymesCo_
body: [@Raktim](/t5/user/viewprofilepage/user-id/4905030) - you can differentiate by specifying the *source* branch and the destination branch in Workzone settings. The required number of successful build will be checked for every PR from the source to destination branch.

Changing the required number of build dynamically when you create the PR (just like adding reviewers) isn't possible AFAIK.


author: Ulrich Kuhnhardt _IzymesCo_
body: As far as I know required build results can only be set to an absolute number in Bitbucket cloud.


Tags: bitbucket-cloud

cloud