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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • workflow-cps-plugin
    • None
    • workflow-cps-plugin 2.39

      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

            Unassigned Unassigned
            jbochenski Jakub Bochenski
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: