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.
Verify it actually works
Terminal
# validate the pipeline definition against your project's CI lint
curl -s --header "PRIVATE-TOKEN: $TOKEN" \
"https://gitlab.com/api/v4/projects/$PROJECT_ID/ci/lint" \
--data-urlencode "content=$(cat .gitlab-ci.yml)"
# then confirm which rules matched on a real pipeline
# CI/CD -> Pipelines -> the run -> each job -> "Trigger"Frequently asked questions
How do I cancel Redundant Pipelines in GitLab CI?
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.
Related guides
How to Cache Maven Dependencies in GitLab CISpeed up GitLab CI Java builds by caching the Maven local repository (.m2) keyed on pom.xml so dependencies
How to Retry a Failing Job in GitLab CIAutomatically retry a failing GitLab CI job with the retry keyword - set max attempts and scope retries to
How to Set a Job Timeout in GitLab CISet a job timeout in GitLab CI with the timeout keyword, how it interacts with the project and runner