How to Deploy Only on the Main Branch in CircleCI
A filters.branches.only: main on the deploy job keeps every other branch running build and test while deploys fire from main alone.
Add a workflow-level branch filter to the deploy job so it is scheduled only on main, leaving the shared build and test jobs unfiltered.
Steps
- Keep build and test jobs without filters so PRs run them.
- Add
filters.branches.only: mainto the deploy job. - Use
requiresso deploy runs after test.
Config
.circleci/config.yml
version: 2.1
workflows:
ci-cd:
jobs:
- build
- test:
requires: [build]
- deploy:
requires: [test]
filters:
branches:
only: mainGotchas
- Branch filters live on the workflow job, not inside the job definition.
- A filtered-out job is simply not scheduled; it does not show as skipped.
Related guides
How to Deploy on a Version Tag in CircleCITrigger a CircleCI deploy only when a version tag like v1.2.0 is pushed using a tag filter plus ignore on bra…
How to Add a Manual Approval Job to a Deploy in CircleCIPause a CircleCI deploy workflow on a type: approval job so a human clicks Approve before the deploy job runs…