Using branch filters
1 week ago1 min read
Cloud
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:
Using Docker? Authenticating Docker pulls from image registries is recommended when using the Docker execution environment. Authenticated pulls allow access to private Docker images, and may also grant higher rate limits, depending on your registry provider. For further information see Using Docker authenticated pulls. |
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