Skip to content

Implement workflow:rules:auto_cancel for CI

Furkan Ayhan requested to merge 436467-workflow-rules-auto_cancel into master

What does this MR do and why?

With workflow:rules:auto_cancel, users will be able to control their CI config's behaviors depending on some conditions (rules).

In this change, besides workflow:rules:auto_cancel:on_new_commit, workflow:rules:auto_cancel:on_job_failure is also implemented. However, since the workflow:auto_cancel:on_job_failure syntax is not used, it is not documented.

This change is behind the existing feature flag ci_workflow_auto_cancel_on_new_commit (#434676 (closed)).

Issue: #436467 (closed)

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

Enable the FF:

Feature.enable(:ci_workflow_auto_cancel_on_new_commit)

Example config;

workflow:
  auto_cancel:
    on_new_commit: interruptible
  rules:
    - if: $CI_COMMIT_REF_PROTECTED == 'true'
      auto_cancel:
        on_new_commit: none
    - when: always                  # Run the pipeline in other cases

test1:
  script: sleep 10
  interruptible: false

test2:
  script: sleep 10
  interruptible: true

In a non-protected branch

Create a pipeline;

Screenshot_2024-01-05_at_13.03.19

Send another commit and see the previous pipeline;

Screenshot_2024-01-05_at_13.06.27

In a protected branch

Create a pipeline;

Screenshot_2024-01-05_at_13.03.19

Send another commit and see the previous pipeline;

Screenshot_2024-01-05_at_13.07.49

Edited by Furkan Ayhan

Merge request reports

Loading