[JIRA] (JENKINS-44808) Unable to print stacktrace on jenkins pipeline

42 views
Skip to first unread message

vasilena.treneva@softwareag.com (JIRA)

unread,
Jan 17, 2019, 4:49:03 AM1/17/19
to jenkinsc...@googlegroups.com
Vassilena Treneva edited a comment on Bug JENKINS-44808
 
Re: Unable to print stacktrace on jenkins pipeline
Hey,

What is the right way to redirect the stacktrace so that a user can see in the console log?

I have this snippet:

{{ try { }}
{{ checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']]) }}
{{ } catch (Throwable ex) { }}
{{ echo 'Caught Throwable. Retrying operation...' }}
{{ echo 'Exception message: ' + ex.getMessage() }}
{{ ex.printStackTrace() }}
{{ retry(5) { }}
{{   checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']]) }}
{{ } }}
{{ } }}

But I cannot see the stacktrace as it goes in the error stream that I do not see in the console build log.

Is there a way to copy this info to the console log?

(My use case: I have many SVN checkout issues and I would like to be able to retry the checkout only when I get SVN related exceptions)

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

vasilena.treneva@softwareag.com (JIRA)

unread,
Jan 17, 2019, 4:49:03 AM1/17/19
to jenkinsc...@googlegroups.com

vasilena.treneva@softwareag.com (JIRA)

unread,
Jan 17, 2019, 4:50:03 AM1/17/19
to jenkinsc...@googlegroups.com
Vassilena Treneva edited a comment on Bug JENKINS-44808
Hey,

What is the right way to redirect the stacktrace so that a user can see in the console log?

{quote} I have this snippet:


{{try {}}
{{ checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']])}}
\{{ } catch (Throwable ex) {}}
\{{ echo 'Caught Throwable. Retrying operation...'}}
\{{ echo 'Exception message: ' + ex.getMessage()}}
\{{ ex.printStackTrace()}}
\{{ retry(5) {}}
{{ checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']])}}
\{{ }}}
\{{ }}}
{quote}
But I cannot see the stacktrace as it goes in the error stream that I do not see in the console build log.

Is there a way to copy this info to the console log?

(My use case: I have many SVN checkout issues and I would like to be able to retry the checkout only when I get SVN related exceptions)

vasilena.treneva@softwareag.com (JIRA)

unread,
Jan 17, 2019, 4:50:03 AM1/17/19
to jenkinsc...@googlegroups.com
Vassilena Treneva edited a comment on Bug JENKINS-44808
Hey,

What is the right way to redirect the stacktrace so that a user can see in the console log?

I have this snippet:

{{try {}}
{{ checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']])}}
\ {{ } catch (Throwable ex) {}}
\ {{ echo 'Caught Throwable. Retrying operation...'}}
\ {{ echo 'Exception message: ' + ex.getMessage()}}
\ {{ ex.printStackTrace()}}
\ {{ retry(5) {}}
{{ checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']])}}
\ {{ }}}
\
{{ }}}

But I cannot see the stacktrace as it goes in the error stream that I do not see in the console build log.

Is there a way to copy this info to the console log?

(My use case: I have many SVN checkout issues and I would like to be able to retry the checkout only when I get SVN related exceptions)

vasilena.treneva@softwareag.com (JIRA)

unread,
Jan 17, 2019, 4:52:01 AM1/17/19
to jenkinsc...@googlegroups.com
Vassilena Treneva edited a comment on Bug JENKINS-44808
Hey,

What is the right way to redirect the stacktrace so that a user can see in the console log?
{quote}
I have this snippet code :

 

{ color:#505f79} { { try \ { }}
try { { checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']])} }
\{{ }
catch (Throwable ex) {}}
\{ { echo 'Caught Throwable. Retrying operation...' }}
\{{
echo 'Exception message: ' + ex.getMessage() }}
\{{
ex.printStackTrace() }}
\{{
retry(5) { }}
{{
checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']])}}
\{{
}}
}
\
{ { color } }}
{quote}
 

 

But I cannot see the stacktrace as it goes in the error stream that I do not see in the console build log.

Is there a way to copy this info to the console log?

(My use case: I have many SVN checkout issues and I would like to be able to retry the checkout only when I get SVN related exceptions)

vasilena.treneva@softwareag.com (JIRA)

unread,
Jan 17, 2019, 4:53:01 AM1/17/19
to jenkinsc...@googlegroups.com
Vassilena Treneva edited a comment on Bug JENKINS-44808
Hey,

What is the right way to redirect the stacktrace so that a user can see in the console log?

I have this code:

 


{color:#505f79}{{
try \{try { checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']])} catch (Throwable ex) \{ echo 'Caught Throwable. Retrying operation...' echo 'Exception message: ' + ex.getMessage() ex.printStackTrace() retry(5) { checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']]) }} {color:#505f79 } } {color}
{code:java}
  // code placeholder
{code}
 

But I cannot see the stacktrace as it goes in the error stream that I do not see in the console build log.

Is there a way to copy this info to the console log?

(My use case: I have many SVN checkout issues and I would like to be able to retry the checkout only when I get SVN related exceptions)

vasilena.treneva@softwareag.com (JIRA)

unread,
Jan 17, 2019, 4:54:02 AM1/17/19
to jenkinsc...@googlegroups.com
Vassilena Treneva edited a comment on Bug JENKINS-44808
Hey,

What is the right way to redirect the stacktrace so that a user can see in the console log?

I have this code:
{code:java}
  // code placeholder

try \ { try { checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']]) } catch (Throwable ex) \ { echo 'Caught Throwable. Retrying operation...' echo 'Exception message: ' + ex.getMessage() ex.printStackTrace() retry(5) { checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'nirdevadm', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${params.branch}@${params.revision}"], [cancelProcessOnExternalsFail: true, credentialsId: 'bgqatest', depthOption: 'infinity', ignoreExternalsOption: true, local: 'gradle', remote: "${external}"]], quietOperation: false, workspaceUpdater: [$class: 'CheckoutUpdater']]) } } {color:#505f79}{color}
{code
:java }
// code placeholder
{code}
 

But I cannot see the stacktrace as it goes in the error stream that I do not see in the console build log.

Is there a way to copy this info to the console log?

(My use case: I have many SVN checkout issues and I would like to be able to retry the checkout only when I get SVN related exceptions)

constantin.bugneac@worldfirst.com (JIRA)

unread,
Mar 4, 2019, 5:58:03 AM3/4/19
to jenkinsc...@googlegroups.com

Has anyone got a proper way to print the stacktrace ?

vasilena.treneva@softwareag.com (JIRA)

unread,
Mar 6, 2019, 2:34:03 AM3/6/19
to jenkinsc...@googlegroups.com

Constantin Bugneac, I managed to get this info like this: 

try {try { ws("${workspaceDirectory}") { checkout() } } catch (Throwable th) { echo 'Caught Throwable' echo 'Exception type: ' + th.getClass() echo 'Exception message: ' + th.getMessage() echo 'Exception stacktrace: ' + th.getStackTrace() as String[] }

constantin.bugneac@worldfirst.com (JIRA)

unread,
Mar 6, 2019, 4:34:01 AM3/6/19
to jenkinsc...@googlegroups.com

peddanet@sonnenkinder.org (JIRA)

unread,
Sep 20, 2019, 7:44:03 AM9/20/19
to jenkinsc...@googlegroups.com

Vassilena Treneva

I am new here, sorry for my poor JAVA knowlegde:

  1. What is the reason for that behavior? Is this a bug or a feature?
  2. If I have nested exceptions, do I have to do it for every nested exeception resp. throwable in this case?
  3. Why is the first Try without a catch?
  4. Most stupid question: Is the ws ("${workspaceDir}"){...} the part I have to replace with my code? . Cause my variable for workspace is different, just to start...

I hope you answer that questions even they are very obvious to you!

Looking forward! Thanks in advance!

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

vasilena.treneva@softwareag.com (JIRA)

unread,
Sep 20, 2019, 8:01:03 AM9/20/19
to jenkinsc...@googlegroups.com

Peter Wein,

  • The reason I wanted to catch the exception was a weird SVN checkout issue that I had – so I wanted to have a retry piece based on whether I have SVN exception or not. Thus I needed to know the type of the exception that occurs.
  • Catching throwable is a bad approach but I did it initially until I figure out what is going in. (throwable covers exceptions as well as errors). Do not do it like me
  • Try without a catch is probably another error in my script.
  • workspaceDir is something that I set at the beginning of my script.

Do you have a specific problem that you are trying to solve by asking me these questions?

peddanet@sonnenkinder.org (JIRA)

unread,
Sep 23, 2019, 12:05:03 PM9/23/19
to jenkinsc...@googlegroups.com

Vassilena Treneva, thanks for the detailed answer.

Yes I have an exception and for example in a code like this:

~~

 try {
 new CommonTools().copyArtifacts(
     env['JOB_NAME'],
     env.ARCHIVE_INPUT_FOLDER + '/JenkinsServerStack/',
     env.JENKINS_SHARE)
 }
 catch (Exception eDF) {
     utility.debugPrint(
         env, name, 'Exception ' + eDF.getClass() + ' : CopyArtifacts somehow failed! ',
            'lastSuccessful()')
     eDF.printStackTrace()
 }

but it does not print the StackTrace. It well gets the class by getClass:

02:55:40 [PolyspaceBugFinder:runSteps]: Exception e is thrown:hudson.AbortException: CopyArtifacts somehow failed! 
lastSuccessful()

So no printStackTrace is printed. What am I doing wrong here?

p.wein@kostal.com (JIRA)

unread,
Sep 23, 2019, 12:59:02 PM9/23/19
to jenkinsc...@googlegroups.com

Which is where we have begun! But I did not understand correctly your way of solving it and if it is a regular pattern of jenkins or workaround for a bug. Is there one filed to the bug tracker team?

me@basilcrow.com (JIRA)

unread,
Sep 24, 2019, 2:25:04 PM9/24/19
to jenkinsc...@googlegroups.com

Another option is to use Throwables#getStackTraceAsString:

try {
  error 'foo'
} catch (err) {
  echo Throwables.getStackTraceAsString(err)
}

Note that this requires approving the following method in Script Security:

staticMethod com.google.common.base.Throwables getStackTraceAsString java.lang.Throwable

jglick@cloudbees.com (JIRA)

unread,
Sep 24, 2019, 3:55:03 PM9/24/19
to jenkinsc...@googlegroups.com

Or hudson.Functions.printThrowable, which displays causes a bit more nicely.

p.wein@kostal.com (JIRA)

unread,
Oct 2, 2019, 3:45:02 AM10/2/19
to jenkinsc...@googlegroups.com

Thank you Basil Crow and Jesse Glick! I have used the proposal of Jesse , and finally it works! 

timblaktu@gmail.com (JIRA)

unread,
Oct 24, 2019, 1:28:05 PM10/24/19
to jenkinsc...@googlegroups.com

Peter Wein Jesse Glick would you post a code example of how you invoke printThrowable, successfully? I'm having trouble finding documentation for the hudson/jenkins functions. (A link would be nice?) Would it be something like this:
node() { try

{ throw "error" }

catch (err) {
hudson.Functions.printThrowable(err)
}
}
??

I also found some good examples [here|https://code-maven.com/jenkins]. Thanks.

timblaktu@gmail.com (JIRA)

unread,
Oct 24, 2019, 1:33:04 PM10/24/19
to jenkinsc...@googlegroups.com
Tim Black edited a comment on Bug JENKINS-44808
{code:java}
 {code}
[~peddanet] [~jglick] would you post a code example of how you invoke printThrowable, successfully? I'm having trouble finding documentation for the hudson/jenkins functions. (A link would be nice?) Would it be something like this:
{code:java}
node() {
  try {
     throw "error"
  }
catch (err) \ {

     hudson.Functions.printThrowable(err)

  }
}

{code }

??

I also found some good examples [here|[https://code-maven.com/jenkins]]. Thanks.

timblaktu@gmail.com (JIRA)

unread,
Oct 24, 2019, 1:33:06 PM10/24/19
to jenkinsc...@googlegroups.com

timblaktu@gmail.com (JIRA)

unread,
Oct 24, 2019, 1:34:03 PM10/24/19
to jenkinsc...@googlegroups.com
Tim Black edited a comment on Bug JENKINS-44808
[~peddanet] [~jglick] would you post a code example of how you invoke printThrowable, successfully? I'm having trouble finding documentation for the hudson/jenkins functions. (A link would be nice?) Would it be something like this:
{code:java}
node() {
    try {
        throw "error"
    }
    catch (err) {
        hudson.Functions.printThrowable(err)
    }
}
{code}
??

Is this function available in default (open source) installations of Jenkins? Do I need to also import anything to make this work?

FWIW, I also
found some good examples [here|[https://code-maven.com/jenkins]]. Thanks.

p.wein@kostal.com (JIRA)

unread,
Oct 28, 2019, 4:09:03 AM10/28/19
to jenkinsc...@googlegroups.com

Tim Black, nearly exactly:

 

 

import hudson.Functions

    
    try {
        throw "error"
    }
    catch (Exception e) {
        println Functions.printThrowable(e)
    }

 

p.wein@kostal.com (JIRA)

unread,
Oct 28, 2019, 4:10:10 AM10/28/19
to jenkinsc...@googlegroups.com
Peter Wein edited a comment on Bug JENKINS-44808
[~timblaktu], nearly exactly:

 
You (or an administrator) must allow this to use this "unsecure" function to work in a jenkinsfile script or pipeline dsl library, then you could use in the following manner:

 
{code:java}

import hudson.Functions

    
    try {
        throw "error"
    }
    catch (Exception e) {
        println Functions.printThrowable(e)
    }
{code}
 

p.wein@kostal.com (JIRA)

unread,
Oct 28, 2019, 4:10:13 AM10/28/19
to jenkinsc...@googlegroups.com
Peter Wein edited a comment on Bug JENKINS-44808
[~timblaktu], nearly exactly:

 You (or an administrator) must allow this to use this "unsecure" function to work in a jenkinsfile script or pipeline dsl library, then you could use in the following manner:

 
{code:java}
import hudson.Functions

[...]     

    try {
        throw "error"
    }
    catch (Exception e) {
        println Functions.printThrowable(e)
    }
{code}
 

p.wein@kostal.com (JIRA)

unread,
Oct 28, 2019, 4:11:02 AM10/28/19
to jenkinsc...@googlegroups.com
Peter Wein edited a comment on Bug JENKINS-44808
[~timblaktu], nearly exactly:

 You (or an administrator) must allow this to use this "unsecure" function to work in a jenkinsfile script or pipeline dsl library, then you could use
the method in the following manner:


 
{code:java}
import hudson.Functions

[...]    
    try {
        throw "error"
    }
    catch (Exception e) {
        println Functions.printThrowable(e)
    }
{code}
 
Reply all
Reply to author
Forward
0 new messages