How to Cancel Redundant Pipelines in GitLab CI
Mark jobs interruptible: true and GitLab auto-cancels them when a newer pipeline starts on the same ref.
Set interruptible: true on jobs that are safe to cancel, with "Auto-cancel redundant pipelines" enabled in settings. Use resource_group to serialize jobs that must not overlap, like deploys.
Interruptible jobs and a deploy resource group
Test jobs are cancellable on a newer push; the deploy uses a resource group so two never run at once.
.gitlab-ci.yml
test:
interruptible: true
script:
- npm ci && npm test
deploy:
resource_group: production
environment: production
script:
- ./deploy.sh
rules:
- if: '$CI_COMMIT_BRANCH == "main"'Gotchas
- Auto-cancel only cancels interruptible jobs; a non-interruptible job (or one already past an interruptible one) keeps running.
- Use
resource_group(not interruptible) to serialize deploys - you want them queued, not cancelled mid-flight. - "Auto-cancel redundant pipelines" must be enabled in Settings > CI/CD for
interruptibleto take effect on new pushes.
Related guides
How to Cancel Superseded Runs with Concurrency in GitHub ActionsCancel superseded GitHub Actions runs with a concurrency group and cancel-in-progress, so a new push to a bra…
How to Conditionally Skip a Job in GitLab CIConditionally run or skip a GitLab CI job with rules: and when: never - branch, variable, and merge-request c…