Using branch filters

1 month ago1 min read
Last updated • Read time
Cloud
This document is applicable to CircleCI Cloud
Server v4+
This document is applicable to CircleCI Server v4+

Branch-filtering to control when job steps will run

Branch filtering has previously only been available for workflows, but with compile-time logic statements, you can also implement branch filtering for job steps.

The following example shows using the pipeline value pipeline.git.branch to control when a step should run. In this case the step run: echo "I am on main" only runs when the commit is on the main branch:

version: 2.1

jobs:
  my-job:
    docker:
      - image: cimg/base:stable
    steps:
      - checkout
      - when:
          condition:
            equal: [ main, << pipeline.git.branch >> ]
          steps:
            - run: echo "I am on main"

workflows:
  my-workflow:
    jobs:
      - my-job