Limit a custom pipeline to a branch

I added two custom pipelines in order to manually trigger them: One for deployment to test and the other for deployment to prod.

Unfortunately, it is possible to run both pipelines on every branch, e.g. I could run "deployment to prod" on the development branch, which should only be possible on the master branch.

Is there a way to limit custom pipelines to specific branches?

2 answers

This doesn't seem to be possible within bitbucket-pipelines.yml itself, but you can check for the branch in your script:


if [ "$(git rev-parse --abbrev-ref HEAD)" == "master" ]; then
echo "master :)"
echo "not master :("

If you want to follow @Steve Taylor's answer you can also check the BITBUCKET_BRANCH environment variable in the pipeline.

Alternatively, you could set up a pipeline that runs on master only and has manual steps that do the deployments. i.e. Steps that will only trigger with manual input. You will also need to be using artifacts for this.

Documentation links.

Manual Steps:


Something like this:

- step:
trigger: manual
name: test
- build-output/**
- ./runTests
- step:
trigger: manual
name: "Deploy to Staging"
- build-output:**
- ./deploy-to-staging
- step:
trigger: manaual
name: "Deploy to Production"
- ./deploy-to-production

- step:
name: test
- ./run-tests

Then you can also set up Bitbucket Deployments (if you're in the alpha programme) to track the status of your environments

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

631 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot