Gitlab: How to cancel redundant pipelines

Updated . Posted . Visible to the public. Repeats.

In the Gitlab settings Show archive.org snapshot the flag Auto-cancel redundant pipelines is enabled by default. This auto-cancels pipelines with jobs that have the interruptible setting set to true (defaults to false e.g. to not cancel deploys by accident).

Consider setting the interruptible flag for test jobs to reduce the load on your runners like in the following example .gitlab-ci.yml:

rubocop:
  interruptible: true
  script:
    - 'bundle exec rubocop'

rspec:
  interruptible: true
  script:
    - 'bundle exec rspec'

Afterwards new pushes to your MR will cancel pending and interruptible running pipelines and start a new pipeline with the current commit.

Note

Running pipelines are only canceled if all running jobs are configured with interruptible: true or no jobs configured with interruptible: false have started at any time. After a job with interruptible: false starts, the entire pipeline is no longer considered interruptible.

Tip

Instead of configuring jobs to be interruptible by default, you can also setup your .gitlab-ci.yml so commit messages with a string like no-ci don't start a new CI pipeline.

Last edit
Katrin
License
Source code in this card is licensed under the MIT License.
Posted by Emanuel to makandra dev (2023-12-19 10:36)