在 Jenkins 管道超时后重试 - 解决方法

mir*_*phd 8 timeout jenkins jenkins-pipeline

这是一个已知的 Jenkins 问题,即管道重试操作在其内部超时时不会重试

retry在超时发生后,肯定有一些解决方法可以强制(或替代)工作?

retry未触发的示例代码:

retry(3) {
  timeout(time: 5, unit: 'MINUTES') {
    // Something that can fail
  }
}
Run Code Online (Sandbox Code Playgroud)

除非被捕获,否则超时错误 ( org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) 会导致整个作业中止。

mir*_*phd 8

一个很好的解决方法,正如Basil Crow 在这里建议的那样,是在超时错误 ( )try - catch 之间 插入retrytimeout使用FlowInterruptedException它,而不将其传递给retry. 一旦我们FlowInterruptedException用自定义错误替换,就会retry启动并开始即使在timeout内部也能正确协作。

例子:

import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException

retry(3) {

  try {

      timeout(time: 5, unit: 'MINUTES') {

        // something that can fail

      } // timeout ends

  } catch (FlowInterruptedException e) {
      // we re-throw as a different error, that would not 
      // cause retry() to fail (workaround for issue JENKINS-51454)
      error 'Timeout!'

  } // try ends

} // retry ends

Run Code Online (Sandbox Code Playgroud)