Was aware of it. Iterating for loops using for(def foo : foos) will work for List. Using closure forEach does not work in Pipeline without using @NonCPS.
- Beware
for (Foo f: foos) loops and Groovy closure-style operators like .each and the like. They will not work right in normal Pipeline script contexts where Pipeline steps are involved directly.
I have been using shell script within for (String f: foos)
for (def file : files) {
sh "scp $file user@$server:$path"
}
This works fine. No problem at all. However this time I had problem iterating through a list of FileWrapper, regardless of existing shell script within or just a simple println of it.
Thus, putting the iteration of FileWrapper within a method annotated with @NonCPS should fix that serializable problem.
However I was unaware the sh step could not be executed within a method annotated with @NonCPS. If that is mentioned in the documentation I must have missed it.
In any case, I have a workaround with first iterating the list of FileWrapper and putting it in a new list of Strings.