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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • 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

            Hide
            abayer Andrew Bayer added a comment -

            I need to nail this down a bit more, but the issue here appears to actually be the handling of a list of arrays - [['Quick', 'Brown']] is a list of lists, but {{['Quick Brown'].collect it.split('\s+') }} is a list of arrays.

            Show
            abayer Andrew Bayer added a comment - I need to nail this down a bit more, but the issue here appears to actually be the handling of a list of arrays - [ ['Quick', 'Brown'] ] is a list of lists, but {{ ['Quick Brown'] .collect it.split('\s+') }} is a list of arrays.

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jbochenski Jakub Bochenski
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated: