Skip to content
Latchkey

How to Auto-Cancel Redundant Builds in CircleCI

CircleCI auto-cancels superseded builds on the same branch when you enable the project setting.

Turn on "Auto-cancel redundant workflows" in Project Settings > Advanced. A new push to a non-default branch then cancels the older in-flight workflow for that branch.

Keep deploy jobs out of cancellation

Auto-cancel is a project setting; for safety, gate deploys to the default branch where auto-cancel does not apply.

.circleci/config.yml
# Project Settings > Advanced > "Auto-cancel redundant workflows": ON
# Applies to non-default branches; a new push cancels the older run.

workflows:
  ci:
    jobs:
      - test
      - deploy:
          requires: [test]
          filters:
            branches:
              only: main   # default branch is exempt from auto-cancel

Gotchas

  • Auto-cancel is a project setting, not YAML - there is no per-workflow cancel-in-progress key like GitHub has.
  • By default it applies to non-default branches, so default-branch deploys are not cancelled mid-flight.
  • Keep deploys on the default branch (or in their own protected flow) so a superseding push cannot cancel a live deploy.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →