Using branch filters
On This Page
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 auth: username: mydockerhub-user password: $DOCKERHUB_PASSWORD # context / project UI env-var reference steps: - checkout - when: condition: equal: [ main, << pipeline.git.branch >> ] steps: - run: echo "I am on main" workflows: my-workflow: jobs: - my-job
Help make this document better
This guide, as well as the rest of our docs, are open source and available on GitHub. We welcome your contributions.
- Suggest an edit to this page (please read the contributing guidefirst).
- To report a problem in the documentation, or to submit feedback and comments, please open an issue on GitHub.
- CircleCI is always seeking ways to improve your experience with our platform. If you would like to share feedback, please join our research community.
Our support engineers are available to help with service issues, billing, or account related questions, and can help troubleshoot build configurations. Contact our support engineers by opening a ticket.
You can also visit our support site to find support articles, community forums, and training resources.
CircleCI Documentation by CircleCI is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.