如何在詹金斯管道中抛出异常? [英] How to throw exception in jenkins pipeline?
本文介绍了如何在詹金斯管道中抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用 try catch 块处理了 Jenkins 流水线步骤.在某些情况下,我想手动抛出异常.但它显示以下错误.
I have handled the Jenkins pipeline steps with try catch blocks. I want to throw an exception manually for some cases. but it shows the below error.
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.io.IOException java.lang.String
我检查了 scriptApproval 部分,没有待批准.
I checked the scriptApproval section and there is no pending approvals.
推荐答案
如果你想在出现异常时中止你的程序,你可以使用管道步骤 error
来停止管道执行并出现错误.示例:
If you want to abort your program on exception, you can use pipeline step error
to stop the pipeline execution with an error. Example :
try {
// Some pipeline code
} catch(Exception e) {
// Do something with the exception
error "Program failed, please read logs..."
}
如果您想以成功状态停止管道,您可能需要某种布尔值来指示您的管道必须停止,例如:
If you want to stop your pipeline with a success status, you probably want to have some kind of boolean indicating that your pipeline has to be stopped, e.g:
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.
}
这篇关于如何在詹金斯管道中抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文