Skip to content
Latchkey

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 interruptible to 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

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card