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?
Thanks
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:
Using these variables, you can do the following at the beginning of your step:
script:
- git checkout $BITBUCKET_PR_DESTINATION_BRANCH
- git merge $BITBUCKET_BRANCH
- <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,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.