Skip to main content

Filter workflows by branch

Filtering jobs by branch

You might come across a scenario where you only need to trigger certain jobs when the merge occurs on a branch. Filters will allow you to define the rules for execution on specific branches.

Branch filtering in workflows

You can filter your jobs to run on specific branches by adding the filters key to the job name in your workflows section.

workflows:
  build:
    jobs:
      - test:
          filters:
            branches:
              only:
                - main

Filters can also be used to prevent later jobs, unless they are running on a specific branch:

workflows:
  build:
    jobs:
      - test
      - deploy:
          requires:
            - test
          filters:
            branches:
              only:
                - main

Additional Resources

Did this answer your question?