Jenkins返回null而不是输出错误

时间:2019-01-30 15:32:05

标签: groovy jenkins-pipeline

有我的代码

def build() {
      try {
// some build gradle task here 
// gradle  install task
}
catch(Throwable err) {
     //   println "DEBUGGGGGGG"

     globalVar.echo "TEST#"


        globalVar.echo "TEST#"
        globalVar.echo err.getMessage()
        globalVar.echo "TEST"
        globalVar.echo err.getCause()
        globalVar.echo "TESTSSSS"

        throw err 
     }
      finally {

}

jenkins我的工作输出:

  

管道]回声       测试#       [管道]回声       测试#       [管道]回声       空值       [管道]回声       测试

     

完成:失败[管道]回显为空[管道]回显TESTSSSS

然后引发异常

  

hudson.model.Run $ RunnerAbortedException         在org.jfrog.hudson.pipeline.common.executors.GradleExecutor.exe(GradleExecutor.java:144)         在org.jfrog.hudson.pipeline.common.executors.GradleExecutor.execute(GradleExecutor.java:69)         在org.jfrog.hudson.pipeline.scripted.steps.ArtifactoryGradleBuild $ Execution.run(ArtifactoryGradleBuild.java:89)         在org.jfrog.hudson.pipeline.scripted.steps.ArtifactoryGradleBuild $ Execution.run(ArtifactoryGradleBuild.java:65)         在org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution $ 1 $ 1.call(AbstractSynchronousNonBlockingStepExecution.java:47)         在hudson.security.ACL.impersonate(ACL.java:290)         在org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution $ 1.run(AbstractSynchronousNonBlockingStepExecution.java:44)         在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)         在java.util.concurrent.FutureTask.run(FutureTask.java:266)         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)         在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)         在java.lang.Thread.run(Thread.java:748)

如何获取异常原因?就我而言,如果我从命令行运行gradle install(没有jenkins)是:  错误:类型不兼容:无法转换为布尔值

但是我会在jenkins作业控制台输出中看到错误

1 个答案:

答案 0 :(得分:1)

尝试-

try{
//your code
}
catch (exc){
println exc
}

为我工作。