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

List isn't iterated when running without @NonCPS

XMLWordPrintable

      This Groovy code doesn't print all items:

      // @NonCPS
      def printList(params) {
          println params
          params.split(",").each { param ->
              println "Param: ${param}"
          }
      }
      text = "Foo,Bar,Baz,Qux"
      printList(text)
      

      Here is the output of non-sandboxed job:

      [Pipeline] echo
      Foo,Bar,Baz,Qux
      [Pipeline] echo
      Param: Foo
      [Pipeline] End of Pipeline
      

      The above code works as expected when invoking using `groovy` command as shown below, but not in Jenkins.

      $ groovy test.groovy 
      Foo,Bar,Baz,Qux
      Param: Foo
      Param: Bar
      Param: Baz
      Param: Qux
      

      In Jenkins the code works as expected only when adding @NonCPS method.

      I don't understand why @NonCPS is needed. This sounds like a bug for me.

            vjuranek vjuranek
            kenorb kenorb
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: