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

Is it possible for a pipeline to run only after a pull request has been approved and merged?

Adam Spain
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!
August 4, 2022

Right now, a pipeline runs as soon as a Pull Request is created. Meaning, it runs before the pull request has been approved or merged. This is not ideal - what if the pull request requires revisions? 

 

Is there a way to specify in the `bitbucket-pipelines.yml` to only deploy upon a merged pull request, rather than as soon as the PR is created? 

 

My current pipeline looks like this:

pipelines:
pull-requests: # The branch pattern under pull requests defines the source branch.
dev:
- step:
name: Deploy to Production
deployment: Production
script:
- do stuff
- deploy stuff
services:
- docker

 

 

For example, in github actions, you can do something like:

prod-push:
if: github.event.action == 'closed' && github.event.pull_request.merged == true

2 answers

1 vote
Brendon Parker August 6, 2022

Sounds like you want the pipeline to run off of the merge to main, not on the pull request. Something like: 

 

pipelines:
branches:
main:
- step:
name: Deploy to Production
deployment: Production
script:
- do stuff
- deploy stuff
services:
- docker
0 votes
Che Fisher June 13, 2024

You might want to look into building a custom Forge app using the newly minted Bitbucket events: https://bitbucket.org/blog/upcoming-changes-to-pull-requests-and-merge-check-configuration

The new `on-merge` event sounds like what you want here - once the PR is approved, hitting the merge button should trigger any on-merge checks. Technically this happens before the merge - if you really do want to hook into the merge event the existing branch trigger functionality should have you covered there.

Good luck!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events