How to Run Conditional Steps by Branch in Bitbucket Pipelines
The branches: block scopes a pipeline to matching branch names, and the condition: key gates a step on changed files.
Under pipelines.branches, key blocks by branch glob (e.g. main, feature/*). Use a step condition: with changesets to skip work when nothing relevant changed.
Branch-specific pipeline and a file condition
main deploys; the deploy step runs only when files under src/ changed.
bitbucket-pipelines.yml
pipelines:
branches:
main:
- step:
name: Deploy
condition:
changesets:
includePaths:
- "src/**"
script:
- ./deploy.sh
'feature/*':
- step:
name: Test
script: [npm ci, npm test]Gotchas
- Branch keys use glob patterns; quote ones with special characters like
feature/*. - The
condition: changesetscheck skips a step when no matching files changed, useful for monorepos. - A push with no matching
branches:block falls back to thedefault:pipeline.
Related guides
How to Build a Monorepo with Conditional Steps in Bitbucket PipelinesBuild only the changed package in a Bitbucket Pipelines monorepo using step condition changesets includePaths…
How to Use Deployment Environments in Bitbucket PipelinesTrack deploys in Bitbucket Pipelines with the deployment key - tag steps as test, staging, or production to p…