如何为詹金斯管道中失败的阶段实施重试选项? [英] How do I implement a retry option for failed stages in Jenkins pipelines?
问题描述
我有一个包含多个阶段的Jenkinsfile,实际上其中一个是另一项工作(部署一项),在某些情况下可能会失败.
I have a Jenkinsfile with multiple stages and one of them is in fact another job (the deploy one) which can fail in some cases.
我知道我可以使用Jenkinsfile进行提示,但是我真的不知道如何为这项工作实现重试机制.
I know that I can made prompts using Jenkinsfile but I don't really know how to implement a retry mechanism for this job.
我希望能够单击失败的阶段并选择重试.
I want to be able to click on the failed stage and choose to retry it.
推荐答案
您应该能够结合使用retry +输入来执行此操作 像这样的东西
You should be able to combine retry + input to do that Something like that
stage('deploy-test') {
try {
build 'yourJob'
} catch(error) {
echo "First build failed, let's retry if accepted"
retry(2) {
input "Retry the job ?"
build 'yourJob'
}
}
}
如果您希望在没有人验证的情况下完成输入,也可以使用超时作为输入. 还有一个waitUntil可能有用,但是我还没有用过
you could also use timeout for the input if you want it to finish if nobody validates. There is also waitUntil that might be useful but i haven't used it yet
WaitUntil似乎绝对是最好的,您应该稍作尝试,但是这样比较干净:
Edit : WaitUntil seems definitely the best, you should play with it a bit but something like that is cleaner :
stage('deploy-test') {
waitUntil {
try {
build 'yourJob'
} catch(error) {
input "Retry the job ?"
false
}
}
}
顺便说一下,这里有doc所有步骤 https://jenkins.io/doc/管道/步骤
By the way, there is doc all of the steps here https://jenkins.io/doc/pipeline/steps
这篇关于如何为詹金斯管道中失败的阶段实施重试选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!