konstunn
konstunn

Reputation: 355

GitLab CD/CD: is there a way to allow to force execute pipeline stage B manually if previous stage A failed, else execute stage B automatically?

Consider GitLab CI/CD pipeline consisting of two consequent stages: A and B.

If stage A succeeds, I want stage B to be executed automatically. But if stage A fails, I don't want stage B to be executed automatically, but still have a possibility to force execute stage B manually.

How can I achive that?

Upvotes: 1

Views: 1359

Answers (2)

makozaki
makozaki

Reputation: 4366

There are at least two ways I can see to achieve that (when your pipeline fails you will need to manually trigger whole pipeline again, not just one stage):

  1. Mark job in stage B when: always to execute job regardless of the status of jobs from prior stages.
firstFailingJob:
  stage: test
  script:
    - echo I will always fail
    - exit 1

secondExecuteWhenManualTrigger:
  stage: deploy
  script:
    - echo I should run even when first failed when triggered manually
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
      when: always
    - when: on_success

Note that the result of whole pipeline will be failed, as ilustrated below. Always execute second job for manual trigger 2. Mark possibly failing job with allow_failure: true to fail without impacting the rest of the CI suite.

firstFailingJob:
  stage: test
  script:
    - echo I will always fail
    - exit 1
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
      allow_failure: true
    - allow_failure: false
...

Result of whole pipeline will be passed with warnings as ilustrated below. Allow failure

$CI_PIPELINE_SOURCE == "web" means pipeline has been triggered from GitLab gui Project page -> CI/CD -> Run Pipeline. You can always setup different conditions with any variable custom or predefined.

Upvotes: 1

Aleksey Tsalolikhin
Aleksey Tsalolikhin

Reputation: 1666

You can't do that with stages.

Jobs of the next stage are run after the jobs from the previous stage complete successfully.

That's per https://docs.gitlab.com/ee/ci/yaml/#stages

There is no way to make a stage be manually triggered.

Upvotes: 0

Related Questions