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

Limit pipelines to a specific branch

James Wallace June 7, 2016

This question is in reference to Atlassian Documentation: Configure bitbucket-pipelines.yml

Is there a way to disable pipelines for specific branches?  Or, only enable for one specific branch?  We'd like to only have pipelines run on our 'master' branch for now, and ignore everything else.  

Tried adding a default that simply has an echo statement in the script, but it still spends a lot of time spinning up a docker, just to do that echo.  Seems like a waste of resources?

2 answers

1 accepted

38 votes
Answer accepted
xtjhin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 7, 2016

Hi James

You sure can limit pipelines to run only when certain branches change.

Here's an example of a bitbucket-pipelines.yml that only runs when master is pushed

pipelines:
  branches:
    master:
      - step:
          script:
            - echo "only on master"

With this configuration, if I push another branch, it won't be built.

James Wallace June 8, 2016

That seems to have done the trick.  I was thinking 'default' was a required block, meaning a branch always has a match.  I was wrong!  

Thank you.

Like # people like this
epoger May 8, 2017

Yup, works for me too, thanks!

Note that the 'default' block is a sibling of the 'branches' block, not a descendant.  That tripped me up for a couple minutes.

Like # people like this
tamer_saleh January 2, 2018

I have a single repository under bit-bucket account and this repository has this 4 branches :

- master 
- API
- Admin - Web

 I put bitbucket-pipelines.yml under master and its like that:

 

image: maven:3.5.0-jdk-7
pipelines:
branches:
API: - step:
caches
: - maven script: - mvn install

 

so I expect that when I push something to API, this will file will be triggered , but in fact it never happened, did I miss any?

Matteo Toto May 22, 2018

is there a way to gave multiple options?
I mean, I want to run the same test on both `develop` and `master`, it's a bit ugly to repeat the same 10 rows of config for both brenches

it'd be great something like this

pipelines:
branches:
API|Admin:
- step:
caches
: - maven script:

but i think it breaks the yaml 

Like # people like this
Georgy Farniev June 6, 2018

Any information about this? We would like to see similar functionality.

Andrew Hudson June 20, 2018

you can write

branches: '{master, develop}': 
Like # people like this
Georgy Farniev June 20, 2018

Wow, didn't know about it, thank you

Like Deleted user likes this
Matteo Toto June 20, 2018

that's incredible, thanks indeed

it is not in any way clear trough the documentation!

Like Mirko Tebaldi likes this
jpkbeddu February 12, 2020

Is it possible to give the multiple branches syntax via bitbucket variables ?

Let say i have a list of branches to trigger pipeline in repo variable APP_BRANCHES with value feature/b1, fix/b2, hotfix/b3

 

branches: '{$APP_BRANCHES}'

 Is it possible ?

3 votes
hishammuneer April 9, 2019
pipelines:
branches:
'{master,dev}':
- step:
# In next line with proper indentation.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events