Skip to content

Cancel a pipeline when configured to auto cancel on first job failure

What does this MR do and why?

This is the second step of #23605 (closed).

  1. Add auto cancel pipeline on job failure syntax ... (!137815 - merged)
  2. <-- HERE -->
  3. Added documentation for workflow:auto_cancel:on... (!145709 - merged)

This MR uses the workflow:auto_cancel:on_job_failure setting that was introduced in !137815 (merged) to stop the pipeline as soon as a job fails.

Screenshots or screen recordings

Screenshot_2024-02-13_at_2.59.19_PM

How to set up and validate locally

Set up a pipeline with the workflow:auto_cancel:on_job_failure set to all and to have more than one job, one of which has to fail. The whole pipeline should be cancelled after the job fails.

This is an example .gitlab-ci.yml

stages:
  - build
  - test
  - deploy

workflow:
  auto_cancel:
    on_job_failure: all

build-a:
  stage: build
  script:
    - echo "Building a..."
    - sleep 5
    - echo "Done"

build-b:
  stage: build
  script:
    - echo "Building b..."
    - exit 1

build-c:
  stage: build
  script:
    - echo "Building c..."
    - sleep 5
    - echo "Done"

build-d:
  stage: build
  script:
    - echo "Building d..."
    - sleep 5
    - echo "Done"

build-e:
  stage: build
  script:
    - echo "Building e..."
    - sleep 5
    - echo "Done"
lint:
  stage: test
  script:
    - echo "Linting..."
    - echo "Done"

deploy:
  stage: deploy
  script:
    - echo "Deploying..."
    - echo "Done..."

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Marco Zille

Merge request reports