我已经使用try catch块处理了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..."
}
如果要以成功状态停止管道,则可能需要使用某种布尔值来指示必须停止管道,例如:
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.
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句