如何为 Jenkins 管道中的失败阶段实施重试选项? [英] How do I implement a retry option for failed stages in Jenkins pipelines?

查看:26
本文介绍了如何为 Jenkins 管道中的失败阶段实施重试选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

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.

解决方案

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'
     }
   }
}

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

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
     }
   }
}

By the way, there is doc all of the steps here https://jenkins.io/doc/pipeline/steps

这篇关于如何为 Jenkins 管道中的失败阶段实施重试选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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