Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-50338

Groovy closure composition doesn't work properly in scripted pipeline

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • groovy-plugin
    • 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):

            vjuranek vjuranek
            grdryn Gerard Ryan
            Votes:
            3 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: