Skip to content

Auto cancel a pipeline when a child pipeline fails

What does this MR do and why?

Related to #23605 (closed).

This MR allows trigger jobs to also auto-cancel the parent pipeline when a child pipeline fails.

In order for this to work:

  • The parent pipeline has to have the auto_cancel:on_job_failure set up to all
  • The trigger jobs need to be set up with strategy: depend

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

N.A.

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

workflow:
  auto_cancel:
    on_job_failure: all

trigger_job_a:
  trigger:
    include: child-pipeline-a.yml
    strategy: depend

trigger_job_b:
  trigger:
    include: child-pipeline-b.yml
    strategy: depend

job_on_parent:
  script:
    - sleep 40

This is an example child-pipeline-a.yml:

# Contents of child-pipeline.yml
workflow:
  auto_cancel:
    on_job_failure: all

job1:
  script: sleep 10

job2:
  script:
    - sleep 5
    - exit 1

This is an example child-pipeline-b.yml:

job1:
  script: sleep 20

job2:
  script:
    - sleep 25
Edited by Marco Zille

Merge request reports