each and collect methods on lists do not work properly

This issue is archived. You can view it, but you can't modify it. Learn more

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
      

            Assignee:
            Unassigned
            Reporter:
            Justin Patrin
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: