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

each and collect methods on lists do not work properly

XMLWordPrintable

      I'm not entirely sure what is happening but it appears that when these methods are called it only runs the closure once and doesn't return the expected values.

      def test() {
          l = ['a', 'b', 'c']
      
          r = []
          for (String v : l) {
              r.add(v)
          }
          println r.join(' ')
      
      
          r = l.collect {
              it
          }
          println r.join(' ')
      }
      
      test()
      

      If I run the above with command-line groovy it does what is expected:

      $ groovy test.groovy
      a b c
      a b c
      

      If I put this in the vars/ directory of a global pipeline library and call is as "test.test()" only the first loop works:

      [Pipeline] echo
      a b c
      [Pipeline] echo
       [Pipeline] End of Pipeline
      Finished: SUCCESS
      

            Unassigned Unassigned
            papercrane Justin Patrin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: