See 
https://github.com/jenkinsci/pipeline-examples/blob/master/docs/BEST_PRACTICES.md#groovy-gotchas




Am Montag, 31. Oktober 2016 12:22:08 UTC+1 schrieb Sverre Moe:
>
> Problem looping through the result of findFiles.
> The result from this method returns a 
> org.jenkinsci.plugins.pipeline.utility.steps.fs.FileWrapper
>
> node {
>     stage("Publish") {        
>         def files = findFiles(glob: '**/*.rpm')
>
>         for (def file : files) {
>             sh "echo Hello World! ${file.path}"
>         }
> }
> Fails with java.io.NotSerializableException: java.util.AbstractList$Itr
>
> Trying to use @NonCPS
> node {
>     stage("Publish") {
>         def files = findFiles(glob: '**/*.rpm')
>         loopFiles(files)
>     }
> }
>
> @NonCPS
> void loopFiles(files) {
>     for (def file : files) { 
>         sh "echo Hello World! ${file.path}"
>     }
> }
> It breaks the loop after first item in list. If 3 files found, then there 
> is only one output.
> However, if I remove the shell script and just use println it loops 
> through all 3 files found.
>
>
> Works if I loop the files first and put the file path in a new list:
> node {
>     stage("Publish") {
>         def files = findFiles(glob: '**/*.rpm')
>         def packages = []
>         for (def file : files) {
>             packages.add(file.path)
>         }
>
>         for (def packagePath : packages) {
>             sh "echo Hello World! ${packagePath}"
>         }
> }
>
> I reckon that FileWrapper is not serializable, hence the problem, but why 
> doesn't the @NonCPS work on all items?
>

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/e665de55-d465-4205-b9ac-a6425bf8b333%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to