-
Bug
-
Resolution: Won't Fix
-
Major
-
Jenkins 2.32.1, Pipeline Groovy 2.29, Groovy 2.4.7, latest Pipeline plugins (as of 03/23/17)
Problem
It seems that in a pipeline, Groovy closures are returned early if you call a method inside them. The closure then only returns the return value of the called method. I provided a minimal sample to reproduce the bug below.
Steps to Reproduce
- Execute the following code in a Jenkins pipeline
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)
- It does not matter if the code is executed in the sandbox or not
- The expected output, as tested with Groovy 2.4.7 locally, is:
- Say: Hello World.
- Jenkins however outputs:
- Hello World.
You may not call CPS-transformed code (such as bar in this example) from inside a GString expression. Use @NonCPS or use string concatenation.