问题
I am working on CICD and for some reason, we want to trigger a job on another job failure.
In yaml file, I have specified "when: on_failure" but I am not able to find a solution to specify job name.
Something like: "when: on_failure: Job_Name".
Now, my 'on failure' job runs on any job failure.
回答1:
If job1
is the first job which may fail and job2
is the next one which should be triggered then I'd suggest the following plan:
- execute
job2
always with no regards if any of previous jobs failed or not ( usewhen: always
for that). - make
job1
to save its result (fail or success) to the artefact file which should be available forjob2
- in
job2
do required actions only based on the content of the artefact from the previous step: if it's failure then do what you need to do, if it's success then just skip. Hope it makes sense.
回答2:
script:
- some commands
- ...
- touch $CI_PROJECT_DIR/success
after_script:
- |
if [ -e success ]; then
echo on success
else
echo on failure
fi
```
来源:https://stackoverflow.com/questions/55630522/how-to-trigger-job-on-specific-job-failure-using-when-on-failure