Skip to content
Latchkey

How to Configure Branch-Specific Pipelines in Bitbucket Pipelines

The branches section maps branch names or glob patterns to their own list of steps, overriding the default pipeline.

Under pipelines.branches, add keys that are exact names or glob patterns (such as feature/*). The most specific match wins; unmatched branches fall back to default.

Steps

  • Add a branches: section under pipelines.
  • Use exact names (main) or globs (release/*) as keys.
  • Keep a default: for branches that match nothing.

bitbucket-pipelines.yml

bitbucket-pipelines.yml
pipelines:
  default:
    - step:
        script:
          - npm test
  branches:
    main:
      - step:
          deployment: production
          script:
            - ./deploy.sh
    'feature/*':
      - step:
          script:
            - npm run test:fast

Gotchas

  • Glob keys with special characters must be quoted in YAML.
  • If a branch matches a branches key, the default pipeline does not also run for it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →