Reputation: 355
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
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):
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.
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.
$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
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