Branch Configuration

You can use branch patterns to ensure pipelines are only triggered when necessary. This guide shows you how to setup branch patterns for whole pipelines and individual build steps.

Pipeline-level branch filtering

By default a pipeline will trigger builds for all branches (* or blank). In your pipeline settings you can set specific branch patterns for the entire pipeline. If a commit doesn't match the branch pattern, no build will be created.

Pull Request Builds

Builds created for pull requests will ignore any pipeline-level branch filters. If you want to limit the branches that can build pull requests, add an additional branch filter in your pipeline's source control settings.

This filter can be found under 'Build pull requests' if you have chosen the 'Trigger builds after pushing code' option.

Step-level branch filtering

As with pipeline-level branch filtering, you can set branch patterns on individual steps. Steps that have branch filters will only be added to builds on branches matching the pattern.

For example, this pipeline.yml file demonstrates the use of different branch filters on its steps:

steps:
  - label: "🔨 Build"
    command: 
      - "npm install"
      - "tests.sh"
    branches: "feature/* release/* master !infrastructure"
  - block: "Release notes"
    prompt: "Please add notes for this release"
    fields:
      - text: "Notes"
        key: "notes"
    branches: "release/*"
  - label: "Deploy Preparation"
    command: "deploy-prep.sh"
    branches: "master"
  - wait
  - trigger: "app-deploy"
    label: "<img class="emoji" title="shipit" alt=":shipit:" src="https://buildkiteassets.com/emojis/img-buildkite-64/shipit.png" draggable="false" />"
    branches: "master"

You can add branch filters to steps created in Buildkite, as well as to steps in your pipeline.yml file.

Screenshot of the Branch Filtering field of a step in Buildkite

Step-level branch filters will only affect the step that they are added to. Subsequent steps without branch filters will still be added to the pipeline.

Branch pattern examples

The following are examples of patterns, and what branches they would match:

  • master production will match master and production only
  • master features/* will match master and any branch that starts with features/
  • */release-123 will match any branch that ends with /release-123 such as feature-123/release-123
  • v*.0 will match branch that begins with a v and ends with a .0, such as v1.0
  • !production will match any branch that's not production (this value should be quoted if defined in a YAML file and uploaded via buildkite-agent pipeline upload)