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

Can a pull request be automatically declined if the build fails ?

Eshwar Iyer
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 29, 2022

Whenever a build fails, the associated pull request should be automatically rejected. Is there any setting for that?

1 answer

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 3, 2022

Hi @Eshwar Iyer,

We don't have such a setting available, however, there may be a solution by using our API to decline a PR:

Are you using Bitbucket Pipelines for your builds? And if so, do you have builds running on pull-requests?

If that's the case, you can include the following after-script in your step:

script:
- <build_commands here>
after-script:
- if [[ $BITBUCKET_EXIT_CODE -ne 0 ]]; then curl -u ${Bitbucket_Username}:${Bitbucket_AppPassword} -X POST https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pullrequests/$BITBUCKET_PR_ID/decline; fi

where Bitbucket_Username and Bitbucket_AppPassword are Repository variables holding the Bitbucket username and app password respectively of a user that has enough permissions to decline a PR. Please note that BITBUCKET_PR_ID is available only for builds that run on pull-requests.

If you have multiple steps, you can add this after-script in all steps.

Please let me know if you're using a different CI/CD system, or if you're using Pipelines but with builds not running on pull-requests (and what you mean by associated PR in this case).

Kind regards,
Theodora

Connor Logan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 1, 2023

Hello @Theodora Boudale !

I was wondering if the solution to this issue is on the roadmap for BitBucket or even if there is an update as of Nov 1, 2023. Ideally an option in settings would be great to prevent Pull Requests from being raised should the build fail.

Hoping to connect with you on this issue and gain some insight.

 

Cheers,

Connor

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 3, 2023

Hi Connor!

I'm afraid that this is not on our roadmap at the moment. We have a feature request about it in our issue tracker that has been closed as a result of inactivity:

You are more than welcome to provide feedback there, as our product managers continue to monitor even closed requests.

Ideally an option in settings would be great to prevent Pull Requests from being raised should the build fail

Could you please explain with an example?

A build running on a pull-requests definition in the yml cannot prevent the creation of a PR, since it is already running on an existing PR.

Do you have a branches pipeline definition running e.g. on feature branch, and are you looking to prevent PR creation with source branch feature if the build on feature fails?

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events