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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


How to fail the Merge if my Pipeline fails that runs after merging the PR to a specific branch


Hi Team,


I am trying to create a pipeline that runs on merge to a target branch. The issue is the pipeline starts deploying only once the PR is merged into the target branch. If the pipeline that is triggered after the merge is failed how can i stop or fail the merge to happen?

Is there a way i can achieve this through any post deploy steps in my pipeline to make sure if the deploy command is failed it stops or fails the merge to happen on the target branch?



1 answer

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Dec 20, 2022

Hi @salluri,

There is no pipeline definition that runs on the merge of pull requests only, so I assume that you have a pipeline that runs on a branch definition, is that the case? Pipelines that run on branches don't have any variables available regarding pull requests and it would be quite difficult to achieve what you are looking for.

You would need to write a script using our API in order to find out which PR it is, based on the merge commit, and even then, you cannot prevent the merge from happening, since it will have already happened. You could possibly reset the last commit and force push back to the Bitbucket repo, but this way you risk losing other commits on the destination branch that were made while the build was running.

What you could do instead is use pull request pipelines, that run when a pull request is created and when the source branch of the pull request gets updated. These pipelines have the following two variables available:

  • $BITBUCKET_PR_ID : the ID of the pull request
  • $BITBUCKET_PR_DESTINATION_BRANCH : the name of the destination branch of the pull request
  • $BITBUCKET_BRANCH is also available, which points to the source branch of the pull request

Using these variables, you can do the following at the beginning of your step:

- <rest of your pipeline>

This way, the build will run in the merge commit (the merge will not occur in the Bitbucket repo, but in the clone of the repo in the Docker container where the pipeline is running). If the build is successful, you can then manually merge the PR on Bitbucket.

Kind regards,

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events