Jenkins - 设置阶段超时并继续下一阶段

Sar*_*gam 1 jenkins jenkins-cli jenkins-pipeline

我有一个在远程节点运行一个 shell 脚本的阶段。如果脚本执行时间很长,则该阶段应等待一段时间,然后移动到下一个阶段,而不会中止后续阶段。

您能否让我知道实现此目的所需的语法。

yor*_*mmi 10

在声明性管道中,添加此阶段:

stage ("do-and-skip-for-timeout") {
   steps {
      script {
        try {
          timeout (time: 10, unit: 'MINUTES') {
             echo "do something here, that can take some time" // replace this line with your code
          }
        }
        catch (error) {
           def user = error.getCauses()[0].getUser()
           if('SYSTEM' == user.toString()) { // SYSTEM means timeout.
             echo "Timeout reached, continue to next stage"
           } 
           else {
             throw new Exception("[ERROR] stage failed!")
           }
        }
   }
}
Run Code Online (Sandbox Code Playgroud)