Skip to content

Instantly share code, notes, and snippets.

@tknerr
Created February 24, 2017 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tknerr/28ca9204bf5a0ec1a72ea13dffcc02e5 to your computer and use it in GitHub Desktop.
Save tknerr/28ca9204bf5a0ec1a72ea13dffcc02e5 to your computer and use it in GitHub Desktop.

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=[]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment