Pipeline: Groovy closure returns early after method call

12 views
Skip to first unread message

Mark J. Becker

unread,
Mar 28, 2017, 4:36:49 AM3/28/17
to Jenkins Users
Hi,

I have a problem executing closures in my pipeline, since they return early. I could break down the problem to the following minimal example:

class Foo {
   
Closure<String> cl = { String a ->
       
return "Say: ${this.bar(a)}"
   
}
   
String bar(String a) {
       
return "Hello ${a}."
   
}
}
Foo f = new Foo()
String output = f.getCl()("World")
echo
(output)

The expected output of this code is "Say: Hello World.", which it returns when I execute it locally in native Groovy. However, in a Jenkins pipeline job the code returns "Hello World.".

I assume that the closure directly returns the output of the this.bar(a) method call.

After having already reported a ticket for this issue, does somebody know more about this issue? Is there a workaround available?


Thanks.
Reply all
Reply to author
Forward
0 new messages