I have a Pipeline job in Jenkins (v2.7.1), where I would like to print each element of the Multi-Line String ( Params) parameter with 3 lines in each line: Foo, Bar, Baz as input.
So, I tried the following syntax (using splitand each):
Params.split("\\r?\\n").each { param ->
println "Param: ${param}"
}
but fail:
java.lang.UnsupportedOperationException: calling public static java.lang.Object org.codehaus.groovy.runtime.DefaultGroovyMethods.each (java.lang.Object, groovy.lang.Closure) in a CPS-converted closure is not yet supported ( JENKINS-26481 ); encapsulate in @NonCPS method or use Java style loops on org.jenkinsci.plugins.workflow.cps.GroovyClassLoaderWhitelist.checkJenkins26481 (GroovyClassLoaderWhitelist.java:90)
which suggest encapsulating in the @NonCPS method or using Java-style loops.
So, I tried to encapsulate in the @NonCPS method, for example:
@NonCPS
def printParams() {
Params.split("\\r?\\n").each { param ->
println "Param: ${param}"
}
}
printParams()
but fail:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: scripts are not allowed to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods println groovy.lang.Closure java.lang.Object
Without a function (according to the first example), adding @NonCPSat the beginning, she complains about an unexpected token.
I also tried the Java style syntax as suggested for the statement (similar here ):
String[] params = Params.split("\\r?\\n")
for (String param: params) {
println "Param: ${param}"
}
which seems to work in normal Groovy, but in Jenkins it does not work:
java.io.NotSerializableException: java.util.AbstractList $ Itr at org.jboss.marshalling.river.RiverMarshaller.doWriteObject (RiverMarshaller.java:860)
, ?