Start Building for Free
CircleCI.comAcademyBlogCommunitySupport

Using branch filters

1+ year ago1 min read
Cloud
Server v4.x
Server v3.x
On This Page
  • Branch-filtering to control when job steps will run

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

Suggest an edit to this page

Make a contribution
Learn how to contribute