我有一个阶段,它在远程节点上运行一个shell脚本。如果脚本执行时间很长,则该阶段应等待一段时间,然后移至下一个阶段,而不会中止后续阶段。
请让我知道实现此目的所需的语法。
答案 0 :(得分:2)
在声明性管道中,添加以下步骤:
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!")
}
}
}
}