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

ComposedClosure not working with List.each

    Details

    • Similar Issues:

      Description

      The following Pipeline code does not yield the expected result.

      def xs = ['1', '2', '3']
      def fix = { it + '-webapp' } >> { echo "ha ${it}" }
      echo "${fix('foobar')}" // works
      xs.each { echo "${it}" } // works
      xs.each fix // fails
      

      Results in the following output:

      [Pipeline] echo
      foobar-webapp
      [Pipeline] echo
      1
      [Pipeline] echo
      2
      [Pipeline] echo
      3
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

      So calling the ComposedClosure works, calling each with a simple Closure works, but calling each with the ComposedClosure does not work.

      The expected result is that calling each with the ComposedClosure yields:

      [Pipeline] echo
      1-webapp
      [Pipeline] echo
      2-webapp
      [Pipeline] echo
      3-webapp
      

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            So I think this is something similar to JENKINS-44924 - ComposedClosure#call is calling delegate.call, but in a non-CPS context, so the old CpsCallableInvocation fun we used to have with any use of .each and friends is showing up again. I don't yet have a good answer on JENKINS-44924, but once I do, it should be easy enough to handle ComposedClosure with a CPS-specific implementation.

            Show
            abayer Andrew Bayer added a comment - So I think this is something similar to JENKINS-44924 - ComposedClosure#call is calling delegate.call , but in a non-CPS context, so the old CpsCallableInvocation fun we used to have with any use of .each and friends is showing up again. I don't yet have a good answer on JENKINS-44924 , but once I do, it should be easy enough to handle ComposedClosure with a CPS-specific implementation.
            Hide
            sterrana Steven Terrana added a comment -

            It seems that the ComposedClosure issue extends beyond iterating via .each. 

             

            The following: 

             

            c = { println "my first closure" }
            println c
            c = c << { println "my second closure" } 
            println c 
            c()
            

            results in: 

            Started by user unknown or anonymous
            Running in Durability level: PERFORMANCE_OPTIMIZED
            [Pipeline] echo
            org.jenkinsci.plugins.workflow.cps.CpsClosure2@753b4e4
            [Pipeline] echo
            org.codehaus.groovy.runtime.ComposedClosure@36c30d6
            [Pipeline] echo
            my second closure
            [Pipeline] End of Pipeline
            Finished: SUCCESS
            

             

             

            Jenkins version:  2.121.2

            workflow-cps version: 2.53

             

            Happy to try to fix if I could be pointed in the general direction to look.  Perhaps by creating a CpsComposedClosure similarly to https://github.com/cloudbees/groovy-cps/blob/master/lib/src/main/java/com/cloudbees/groovy/cps/impl/CpsClosure.java ? 

             

            Thanks,

            Steven Terrana

             

            Show
            sterrana Steven Terrana added a comment - It seems that the ComposedClosure issue extends beyond iterating via .each.    The following:    c = { println "my first closure" } println c c = c << { println "my second closure" } println c c() results in:  Started by user unknown or anonymous Running in Durability level: PERFORMANCE_OPTIMIZED [Pipeline] echo org.jenkinsci.plugins.workflow.cps.CpsClosure2@753b4e4 [Pipeline] echo org.codehaus.groovy.runtime.ComposedClosure@36c30d6 [Pipeline] echo my second closure [Pipeline] End of Pipeline Finished: SUCCESS     Jenkins version:  2.121.2 workflow-cps version: 2.53   Happy to try to fix if I could be pointed in the general direction to look.  Perhaps by creating a CpsComposedClosure similarly to https://github.com/cloudbees/groovy-cps/blob/master/lib/src/main/java/com/cloudbees/groovy/cps/impl/CpsClosure.java  ?    Thanks, Steven Terrana  

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                pmr Philipp Moeller
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: