Start next job when one of the previous manual jobs are a success

Viewed 464

I have the following job structure:

JOB_A:
  stage: versioning
  only:
    - main

JOB_B_MANUAL:
  stage: versioning
  needs:
    - JOB_A
  only:
    - main
  when: manual
  allow_failure: true

JOB_C_MANUAL:
  stage: versioning
  needs:
    - JOB_A
  only:
    - main
  when: manual
  allow_failure: true

JOB_D_MANUAL:
  stage: versioning
  needs:
    - JOB_A
  only:
    - main
  when: manual
  allow_failure: true

JOB_E_MANUAL:
  stage: versioning
  needs:
    - JOB_B
    - JOB_C
    - JOB_D
  only:
    - main
  when: on_success

How can I set this up to to:

  • Make JOBS B, C, D start JOB_E when one of them is manually executed and is a succes?

Thanks

1 Answers

According to the doc: https://docs.gitlab.com/ee/ci/yaml/#when

Possible inputs:

  • on_success (default): Run the job only when all jobs in earlier stages succeed or have allow_failure: true.
  • manual: Run the job only when triggered manually.
  • always: Run the job regardless of the status of jobs in earlier stages. Can also be used in workflow:rules.
  • on_failure: Run the job only when at least one job in an earlier stage fails.
  • delayed: Delay the execution of a job for a specified duration.
  • never: Don’t run the job. Can only be used in a rules section or workflow: rules.

If I understood well what you want to do, this following use case is missing: on_at_least_one_success: Run the job only when at least one job in earlier stages succeed. This could be a nice feature to propose ;)

However, if you do not have any concerns to put the JOB_E in a separated pipeline, here maybe a solution for you, hope it could be your workaround:

Project: my-test/ops/job-dependency

stages:
  - versioning

JOB_A:
  stage: .pre
  script:
    - echo "JOB_A_MANUAL"  

JOB_B_MANUAL:
  stage: versioning
  script:
    - echo "do something"
  needs:
    - JOB_A
  when: manual

JOB_B_MANUAL_TRIGGER:
  stage: .post
  trigger:
    project: my-test/ops/job-dependency-child
  needs:
    - JOB_B_MANUAL

JOB_C_MANUAL:
  stage: versioning
  script:
    - echo "do something"
  needs:
    - JOB_A
  when: manual

JOB_C_MANUAL_TRIGGER:
  stage: .post
  trigger:
    project: my-test/ops/job-dependency-child
  needs:
    - JOB_C_MANUAL

JOB_D_MANUAL:
  stage: versioning
  script:
    - echo "do something"
  needs:
    - JOB_A
  when: manual

JOB_D_MANUAL_TRIGGER:
  stage: .post
  trigger:
    project: my-test/ops/job-dependency-child
  needs:
    - JOB_D_MANUAL

Project: my-test/ops/job-dependency-child

stages:
  - post

JOB_E:
  stage: post
  script:
    - echo "do something"

enter image description here

Related