Jenkins Pipeline带条件的retry步骤报错问题求助
Jenkins Pipeline中retry步骤带条件使用的问题及解决
我在Jenkins Pipeline中尝试使用带条件的retry步骤时遇到报错:
报错1:添加conditions参数时
WorkflowScript: 56: Invalid parameter "conditions", did you mean "count"? @ line 56, column 27. retry(count: 120, conditions: !Jenkins.instance.getItem('secret-name-of-job').getLastBuild().getExecution().isComplete()) { ^
报错2:不指定conditions参数时
WorkflowScript: 56: Arguments to "retry" must be explicitly named. @ line 56, column 9. retry(count: 120, !Jenkins.instance.getItem('secret-name-of-job').getLastBuild().getExecution().isComplete()) {
原Jenkinsfile代码
steps { retry(count: 120, conditions: !Jenkins.instance.getItem('secret-name-of-job').getLastBuild().getExecution().isComplete()) { echo "Sleeping for 1 minute since e2e build is running..." sleep(time: 1, unit: 'MINUTES') } // more code }
编辑补充:成功实现的代码
在@ycr的帮助下,我成功实现了等待其他任务完成的功能,代码如下:
script { retry(count: 120) { if (Jenkins.instance.getItem('magic-secret-job').getLastBuild().getExecution().isComplete() == false) { echo "Waiting since e2e build is running..." sleep(time: 1, unit: "MINUTES") throw new Error('e2e is still running') } } // some_other_code }
结论
- 若要在retry中使用if/循环,需将其置于script块内
- 首次创建条件时可能失败,需在“In-process Script Approval”中批准相关方法
- 需抛出异常以触发重试
- 仍不清楚conditions参数的工作机制,正如@ycr所说,它应为ErrorCondition的某种扩展
内容的提问来源于stack exchange,提问作者Mefistis
相关产品推荐
相关产品推荐

