I have a class that exposes a each style function that is working fine when
called from many places of Jenkinsfile, but one such call needs to process
it in reverse order, so I created a reverseEach style function, but this
started throwing "java.io.NotSerializableException:
org.codehaus.groovy.runtime.ReverseListIterator" exception. Here is the
working function (order is just a list of strings):
public List<String> eachDef(def body) {
return order.each { name ->
def bom_def = getDef(name)
if (bom_def.enabled) {
body.call(name, bom_def)
}
}
}
Here is the reverse style function that uses reverseEach:
public List<String> reverseEachDef(def body) { return order.reverseEach {
name -> def bom_def = getDef(name) if (bom_def.enabled) { body.call(name,
bom_def) } } }
I even tried an alternative reverse but got the same error:
public List<String> reverseEachDef(def body) { // NOTE: list.reverse() is
not currently whitelisted:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:
Scripts not permitted to use staticMethod
org.codehaus.groovy.runtime.DefaultGroovyMethods reverse java.util.List
return order.iterator().reverse().each { name -> def bom_def = getDef(name)
if (bom_def.enabled) { body.call(name, bom_def) } } }
As a workaround, I used a plain for loop and it worked:
public List<String> reverseEachDef(def body) {
// NOTE: reverseEach() caused some weird:
java.io.NotSerializableException:
org.codehaus.groovy.runtime.ReverseListIterator
for (int i = order.size() - 1; i >= 0; --i) {
String name = order[i]
def bom_def = getDef(name)
if (bom_def.enabled) {
body.call(name, bom_def)
}
}
}
Looks like the issue in https://issues.jenkins-ci.org/browse/JENKINS-27421
but not fully addressed (as stated by some of the latest comments)?
I am running the following versions:
Jenkins: 2.89.3
Pipeline: 2.5
Script Security: 1.50
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/7ab5bd1b-012c-4f9b-8f67-11473e113fb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.