https://jenkins.io/zh/doc/pipeline/tour/agents/
Jenkinsfile (Declarative Pipeline) pipeline { agent any stages { stage('Deploy') { steps { retry(3) { sh './flakey-deploy.sh' } timeout(time: 3, unit: 'MINUTES') { sh './health-check.sh' } } } } }
“Deploy”阶段(stage)重试运行 flakey-deploy.sh
脚本3次,等待health-check.sh
脚本执行最多3分钟。
如果 health-check.sh
脚本在3分钟内没有完成,Pipeline将会标记在“Deploy”阶段失败。
我们也可以组合这些步骤。例如,如果我们想要重试部署任务5次,但是总共花费的时间不能超过3分钟:
steps { timeout(time: 3, unit: 'MINUTES') { retry(5) { sh './flakey-deploy.sh' }