如何使用" when:on_failure& quot;触发特定作业失败的作业? [英] How to trigger job on specific job failure using "when: on_failure"?

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

问题描述

我正在处理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& quot;触发特定作业失败的作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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