Logging to the console output from a trusted global pipeline library

547 views
Skip to first unread message

Sean McNamara

unread,
Oct 22, 2016, 9:33:16 AM10/22/16
to jenkins...@googlegroups.com
Hello,

I'm trying to print to the console output tab of a running pipeline
project from a global pipeline library. My understanding is that the
only way to do this is via the echo step.

What I have is a bunch of more "sophisticated" Groovy code (such as -
*gasp!* - loops) that doesn't work under the CPS interpreter, so I
have *most* of my global pipeline library's methods annotated with
@NonCPS.

However, I have a CPS-interpreted class that looks like this:

class Stepper implements Serializable {
static def steps
static def log(o) { Stepper.steps.echo o; }
}

When I call Stepper.log "hi" from other classes in the global pipeline
library (mostly from @NonCPS methods), it works fine the *first* time.
But every subsequent call to Stepper.log does not print to the console
output.

Interestingly, the job succeeds; no exception is thrown on the JVM
stdout/stderr; and no complaining messages are printed to the console
output. It just... silently eats my echo steps.

Am I doing something wrong, or is this by design?

My environment is:

Jenkins 2.19.1 running on Oracle JDK 8u112 64-bit on Windows 10
64-bit. Started with java -jar jenkins.war

Thanks,

Sean

Sean McNamara

unread,
Oct 22, 2016, 9:36:37 AM10/22/16
to jenkins...@googlegroups.com
Amendment below; I omitted some information...

On Sat, Oct 22, 2016 at 9:33 AM, Sean McNamara <smc...@gmail.com> wrote:
> Hello,
>
> I'm trying to print to the console output tab of a running pipeline
> project from a global pipeline library. My understanding is that the
> only way to do this is via the echo step.
>
> What I have is a bunch of more "sophisticated" Groovy code (such as -
> *gasp!* - loops) that doesn't work under the CPS interpreter, so I
> have *most* of my global pipeline library's methods annotated with
> @NonCPS.
>
> However, I have a CPS-interpreted class that looks like this:
>
> class Stepper implements Serializable {
> static def steps
> static def log(o) { Stepper.steps.echo o; }
> }


I *also* have the following in my pipeline script, after the @Library
and import statements:

Stepper.steps = this

node {
DriverMethods.main(param) // Kicks off the complex code in the
global pipeline library, passing a build parameter to it

Baptiste Mathus

unread,
Oct 26, 2016, 8:59:01 AM10/26/16
to jenkins...@googlegroups.com
Hi,
IIUC you try to call a step (echo) from nonCPS, this is not supported. 

HTH

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPAActdyw9-12pW%3D5%2BopeXTDOzcrtATny38thwecQaO6VABRzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages