我们有一个Jenkins管道脚本,在所有准备步骤完成之后,在实际应用更改之前,需要用户的批准。
我们要在此步骤中添加一个超时,以便如果用户没有输入,则构建将中止,并且当前正在使用这种方法进行工作:
try {
timeout(time: 30, unit: 'SECONDS') {
userInput = input("Apply changes?")
}
} catch(err) {
def user = err.getCauses()[0].getUser()
if (user.toString == 'SYSTEM') { // if it's system it's a timeout
didTimeout = true
echo "Build timed out at approval step"
} else if (userInput == false) { // if not and input is false it's the user
echo "Build aborted by: [${user}]"
}
}
Run Code Online (Sandbox Code Playgroud)
该代码基于以下示例:https : //support.cloudbees.com/hc/en-us/articles/226554067-Pipeline-How-to-add-an-input-step-with-timeout-that-continues -如果超时使用默认值和其他在线位置达到,但是我真的不喜欢捕获所有错误然后使用找出导致异常的原因err.getCauses()[0].getUser()。我宁愿明确catch(TimeoutException)或类似的东西。
所以我的问题是,批准步骤超时或userInput为false会引发哪些实际异常?到目前为止,我还无法在文档或Jenkins代码库中找到任何东西。