-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
Jenkins 2.89.4
Closure composition works as expected in a regular Groovy shell, and also in the Jenkins script console; but if I run it in a pipeline I get odd results. My assumption is that however closures work in Pipeline, the leftshift / rightshift operators aren't overloaded to perform composition, but that's just a guess and I really don't know what I'm talking about.
I think it'd be cool if it worked the same way
Example (adapted from the Groovy docs):
def plus2 = { it + 2 } def times3 = { it * 3 } def times3plus2 = plus2 << times3 println "${times3plus2(3)} == 11" println "${times3plus2(4)} == ${plus2(times3(4))}" def plus2times3 = times3 << plus2 println "${plus2times3(3)} == 15" println "${plus2times3(5)} == ${times3(plus2(5))}" // reverse composition println "${times3plus2(3)} == ${(times3 >> plus2)(3)}"
Pipeline output (incorrect):
Script console (correct):
I hit this same issue trying to use composition after verifying that it worked in script console. There is actually nothing odd about the result, it just stops at the first closure in the chain. This is true even for rightshift composition.