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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I prevent two pipelines from running on pull requests?

Edited

 

Pipeline requirements:

- We have branches for our development-staging (dev), staging, and production (release) environments.

- For every pull request, we want to run build and test steps before it gets merged into the target branch, to ensure that we don't merge broken code.

- Once a PR is merged into an environment branch, the branch is built, tested, and deployed.

 

The problem:

When I open a PR to merge master into staging (or staging into release), two pipelines are triggered: one for the PR and one for master branch. This triggers the deploy step for the master branch unnecessarily. 

The documentation mentions this, but doesn't give any direction on how to prevent the two pipelines from running. 

Is there a way to check if it's a pull request inside the master pipeline definition and cancel the pipeline if it is?

 

Here's the relevant part of my `bitbucket-pipelines.yml` file:

pipelines:  
pull-requests:    
'**':      
step*build-test
  
branches:    
master:      
step*build-test      
step          
<<*docker          
deploymentDev

staging:      
step*build-test      
step:          
<<*docker          
deploymentStaging

release
:      
step*build-test

tags:    
v*:      
step*build-test      
step:          
<<*docker          
deploymentProduction          
triggermanual

1 answer

0 votes

Hi @david-cofi  and welcome to the community!

If you open a PR without pushing any new commits to master, only the pull-requests pipeline should run, and not the master one.

Could you please let me know how you open the PR? From Bitbucket UI? Or are you doing something different?

Or are you perhaps pushing commits to master, when an existing PR with master as source branch is open? Because in this case, if you push commits to master when a PR is already open, two builds will indeed run.

In this case, you can avoid the duplicate builds by including the text [skip ci] anywhere in the commit message of the latest commit you are pushing to master. If you do that, when you push to master, only the pull-requests build will run (for the open PR) and no build will run for master.

If this is not your use case, please provide some further info on the exact steps you take so we can further investigate.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
Community showcase
Published in Jira Service Management

Security Advisory for Jira Service Management

On October 20, 2021, Atlassian published a security advisory for Jira Service Management. The full advisory is available at this link.  We've seen a number of questions already asking for...

76 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you