Missed Team ’24? Catch up on announcements here.

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

How to only run a pipeline for a PR and not also for the source branch?

George Boot February 27, 2019

I have Pipelines configured to run for all `feature/**` branches and also for PR's.

When I create a PR, 2 pipelines are triggered: one for the PR, one for the source branch.

The reason for my setup is that I want development feedback asap when developing in a `feature/**` branch. Then, once the developer creates as PR, only that pipeline should run (otherwise it's just a waste to run 2 almost identical pipelines).

Any suggestions?

1 answer

0 votes
Marty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 27, 2019

Hi George,

I am not on the Bitbucket team, but I will try to help.

When you say you have configured pipelines to run "for a PR" do you mean for the target branch?

Eg. Let's say your target branch is called master.  Then you create a feature branch called feature/123.  You do some work on the feature branch, add some commits, push the changes and then create a Pull Request from feature/123 -> master.  When does a pipeline get triggered?

George Boot February 28, 2019

Let me show you my `bitbucket-pipelines.yml`:

image: thecodingmachine/php:7.3-v2-cli-node10

stepdefinitions:
- Build: &Build
name: 'Build'
# etc

pipelines:

feature/*:
- step: *Build
# etc

pull-requests:
'**':
- step: *Build
# etc

branches:
master:
- step: *Build
# etc

 So, as you can see, we have 3 triggers: a one for `feature/*`, one for pull-requests (all branches) and one for master specific.

When I start developing on a `feature/my-awesome-feature`, for every push I do, it will run the pipeline for `feature/*`, as expected.

Then, when I create a pull request to merge that feature into master, it will run 2 pipeline: the `feature/*` one and also the pull-request one.

What I want to archive, is keep on running the `feature/*` one during dev, but for the PR, it should only run the PR one.

Will that be possible?

Like Marty likes this
Marty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 28, 2019

Hi George,

I think you can just remove the 

pull-requests:
'**':
- step: *Build
# etc

from your pipelines and you will get the desired behaviour.

I hope that helps!

George Boot February 28, 2019

Hi Martyn,

 

I don't think thats exactly the same.

 

The branch pipeline only tests the code in the branch as it is, whereas the pr pipelines performs a merge into the destination branch and then runs the pipeline. Meaning, it will test the situation that will exist after the merge. Or at least, that is my understanding of it.

Like Marty likes this
Marty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 28, 2019

You're right, TIL!

https://bitbucket.org/blog/faster-feedback-on-merges-with-pull-request-pipelines

That sounds like a very useful build to run.

Why do you need branch builds then?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events