Groovy+pipeline: why does executing step exit function?

107 views
Skip to first unread message

Oleh Olkhovskyy

unread,
Feb 4, 2016, 11:45:21 AM2/4/16
to Jenkins Users
Hi,

I'm writing a pipeline groovy script. and stumbled upon this problem:

If I try to run step within a function, then function is immediately terminated and doesn't execute following instructions.
I.e.

I have function:

@NonCPS
def getBuildOutput(build_job) {
    echo "BeforeStep"
    def prop_file=readFile('get_src_job_artifacts/output.properties')
    echo "AfterStep"
    //Execute further processing with non serializable variables
    //....


But when I call it, "BeforeStep" is echoed, but "AfterStep" is not.
instead getBuildOutput returns string read from that file.
Why is that, and is there a way to avoid that?



Brian Ray

unread,
Feb 4, 2016, 11:54:28 AM2/4/16
to Jenkins Users
It's because of the @NonCPS annotation. It's incompatible with pipeline step calls. See more here.

Oleh Olkhovskyy

unread,
Feb 5, 2016, 5:11:13 AM2/5/16
to Jenkins Users
Aah, I missed that sentence when was reading tutorial. Indeed calling from normal function works as expected.

Thanks!
Reply all
Reply to author
Forward
0 new messages