title: How to print each element of Multi-line String Parameter?
body: <p>I've Pipeline job in Jenkins (v2.7.1) where I'd like to print each element of Multi-line String parameter (<code>Params</code>) with 3 strings in each line: <em>Foo</em>, <em>Bar</em>, <em>Baz</em> as an input.</p>
  
  <p>So I've tried the following syntax (using <a href="https://stackoverflow.com/a/454913"><code>split</code></a> and <code>each</code>):</p>
  
  <pre><code>Params.split("\\r?\\n").each { param -&gt;
      println "Param: ${param}"
  }
  </code></pre>
  
  <p>but it fails with:</p>
  
  <blockquote>
    <p><code>java.lang.UnsupportedOperationException</code>: Calling public static java.lang.Object
    org.codehaus.groovy.runtime.DefaultGroovyMethods.each(java.lang.Object,groovy.lang.Closure) on a CPS-transformed closure is not yet supported (<a href="https://issues.jenkins-ci.org/browse/JENKINS-26481" rel="nofollow noreferrer">JENKINS-26481</a>); encapsulate in a @NonCPS method, or use Java-style loops
        at org.jenkinsci.plugins.workflow.cps.GroovyClassLoaderWhitelist.checkJenkins26481(GroovyClassLoaderWhitelist.java:90)</p>
  </blockquote>
  
  <p>which suggest to <em>encapsulate in a @NonCPS method, or use Java-style loops</em>.</p>
  
  <hr>
  
  <p>So I've tried to <em>encapsulate in a @NonCPS method</em> like:</p>
  
  <pre><code>@NonCPS
  def printParams() {
      Params.split("\\r?\\n").each { param -&gt;
          println "Param: ${param}"
      }
  }
  printParams()
  </code></pre>
  
  <p>but it fails with:</p>
  
  <blockquote>
    <p>org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods println groovy.lang.Closure java.lang.Object</p>
  </blockquote>
  
  <p>Without the function (as per first example), adding <code>@NonCPS</code> at the beginning it complains about <em>unexpected token</em>.</p>
  
  <hr>
  
  <p>I also tried Java-style syntax as suggested by using <em>for</em> operator (similar as <a href="https://stackoverflow.com/a/14449414/55075">here</a>):</p>
  
  <pre><code>String[] params = Params.split("\\r?\\n")
  for (String param: params) {
      println "Param: ${param}"
  }
  </code></pre>
  
  <p>which seems to work in plain Groovy, but it fails in Jenkins with:</p>
  
  <blockquote>
    <p><code>java.io.NotSerializableException</code>: java.util.AbstractList$Itr
        at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)</p>
  </blockquote>
  
  <hr>
  
  <p>Which syntax I should use to make it work?</p>