我已经使用 try catch block 处理了 Jenkins 管道步骤。在某些情况下,我想手动抛出异常。但它显示以下错误。
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.io.IOException java.lang.String
我检查了 scriptApproval 部分,没有待批的批准。
最佳答案
如果您想在出现异常时中止程序,可以使用管道步骤 error
停止管道执行并出现错误。例子 :
try {
// Some pipeline code
} catch(Exception e) {
// Do something with the exception
error "Program failed, please read logs..."
}
如果您想以成功状态停止管道,您可能需要某种 bool 值来指示您的管道必须停止,例如:
boolean continuePipeline = true
try {
// Some pipeline code
} catch(Exception e) {
// Do something with the exception
continuePipeline = false
currentBuild.result = 'SUCCESS'
}
if(continuePipeline) {
// The normal end of your pipeline if exception is not caught.
}
关于jenkins - 如何在 Jenkins 管道中抛出异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42718785/