Jenkins-将超时设置为Stage并继续进行下一阶段

问题描述 投票:-2回答:1

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

请让我知道实现此目的所需的语法。

jenkins jenkins-pipeline jenkins-cli
1个回答
0
投票

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

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!")
           }
        }
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.