jenkins - 如何在 Jenkins 管道中抛出异常?

标签 jenkins jenkins-plugins jenkins-pipeline

我已经使用 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/

相关文章:

linux - Chromedriver 手动工作,但从 Jenkins Slave 运行时失败

jenkins - 如何使用配置文件提供程序插件从 Jenkins 管道内的配置文件中读取属性

jenkins - Jenkins 中的构建超时插件 : how long is 'too long' ?

jenkins - 清理/var/lib/jenkins/caches 文件夹

groovy - 在 Groovy 中访问闭包之外的变量

Jenkins 管道如何更改到另一个文件夹

git - Jenkins 每个分支部署

git - 如何在Jenkins中更改构建开始文件夹

Jenkins:如何设置GitHub组织下作业的周期扫描间隔?

rest - 使用REST检查jenkins中的文件夹中是否存在作业