如何使用“ when:on_failure”在特定作业失败时触发作业? [英] How to trigger job on specific job failure using "when: on_failure"?

查看:182
本文介绍了如何使用“ when:on_failure”在特定作业失败时触发作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究CICD,由于某种原因,我们想在另一个作业失败时触发一个作业。

I am working on CICD and for some reason, we want to trigger a job on another job failure.

在yaml文件中,我指定了 when:on_failure,但找不到解决方案来指定作业名称。

In yaml file, I have specified "when: on_failure" but I am not able to find a solution to specify job name.

类似的东西:当:on_failure:Job_Name。

Something like: "when: on_failure: Job_Name".

现在,我的失败时作业运行

Now, my 'on failure' job runs on any job failure.

推荐答案

如果 job1 是第一个作业,可能会失败,并且下一个应该触发 job2 ,然后我建议以下计划:

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:


  • 执行 job2 始终不考虑先前的任何作业是否失败(请使用 when:Always
  • 制作 job1 来将其结果(失败或成功)保存到工件文件中,该文件应可用于 job2
  • job2 中的
  • 仅根据人工制品的内容执行所需的操作从上一步开始:如果失败,则执行您需要做的事情;如果成功,则跳过。
    希望有道理。

  • 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.

这篇关于如何使用“ when:on_failure”在特定作业失败时触发作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆