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

.collect, then .each still results in closure being invoked only for first element

    Details

    • Type: Bug
    • Status: Open
    • Priority: Critical
    • Resolution: Unresolved
    • Component/s: workflow-cps-plugin
    • Labels:
      None
    • Environment:
      workflow-cps-plugin 2.39
    • Similar Issues:

      Description

      Running this Jenkinsfile

      def lines2 = [['Quick', 'Brown']]
      echo "Literal toString():" + lines2
      def result2 = ''
      lines2.each{ result2 += it }
      echo "Literal each: " + result2
      
      @NonCPS def test(){
          def lines = ['Quick Brown'].collect{ it.split('\\s+') }
          echo "NonCps toString()" + lines
          def result = ''
          lines.each{ result += it }
          echo "NonCps each: " + result
      }
      test()
      
      def lines = ['Quick Brown'].collect{ it.split('\\s+') }
      echo "Collect toString():" + lines
      def result = ''
      lines.each{ result += it }
      echo "Collect each: " + result

      Results in

      [Pipeline] echo
      Literal toString():[[Quick, Brown]]
      [Pipeline] echo
      Literal each: [Quick, Brown]
      [Pipeline] echo
      NonCps toString()[[Quick, Brown]]
      [Pipeline] echo
      NonCps each: [Quick, Brown]
      [Pipeline] echo
      Collect toString():[[Quick, Brown]]
      [Pipeline] echo
      Collect each: Quick
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

      As you can see calling .each on a literal list works correctly, but calling it on a result of .collect still fails like JENKINS-26481

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                jbochenski Jakub Bochenski
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: