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.

Related guides

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