I was trying to get more meaningful stack traces, but it seems that the exception we catch does not carry any more specific details about the step that failed. The only info we get is that the pipeline step failed and the exit code it failed with.
Example pipeline code snippet:
node {
try {
stage('do-stuff') {
sh "echo do somehing; exit 0"
}
} catch(ex) {
echo "ooops - caught: ${ex.class}"
echo "ooops - with msg: ${ex.message}"
echo "ooops - backtrace: ${ex.stackTrace}"
}
}
In the above example, the sh
step fails with this message printed to stdErr:
[workspace] Running shell script
/var/lib/jenkins/jobs/exer/workspace@tmp/durable-5ce5044c/script.sh: 2: /var/lib/jenkins/jobs/exer/workspace@tmp/durable-5ce5044c/script.sh: Syntax error: "do" unexpected
However, the exception details printed out only tell us this (which is, except for the exit code, basically the same message for any sh
step that fails):
[Pipeline] echo
ooops - caught: class hudson.AbortException
[Pipeline] echo
ooops - with msg: script returned exit code 2
[Pipeline] echo
ooops - backtrace: [org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution$3.call(DurableTaskStep.java:327), org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution$3.call(DurableTaskStep.java:306), org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution$4.call(DurableTaskStep.java:359), java.util.concurrent.FutureTask.run(FutureTask.java:266), java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142), java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617), java.lang.Thread.run(Thread.java:745)]
When you dump the exceptions properties via ex.dump()
you can see that it carries no more details about the failed sh
step (the actual command that was being executed and the stdout / stderr would be the missing things we are interested in, but it's not there unfortunately :-/):
<hudson.AbortException@531f4b0e detailMessage=script returned exit code 2 cause=null stackTrace=[org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution$3.call(DurableTaskStep.java:327), org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution$3.call(DurableTaskStep.java:306), org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution$4.call(DurableTaskStep.java:359), java.util.concurrent.FutureTask.run(FutureTask.java:266), java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142), java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617), java.lang.Thread.run(Thread.java:745)] suppressedExceptions=[]>