How to trigger job on specific job failure using “when: on_failure”?

时光总嘲笑我的痴心妄想 提交于 2020-08-10 23:20:48

问题


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 ( use when: always for that).
  • make job1 to save its result (fail or success) to the artefact file which should be available for job2
  • 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!