Hi Robin,

The simplest Groovy idiom for iterating over a collection is

hostnames.each { host ->
  do something interesting with host ...
}



Does this work?

Brian

On Monday, February 9, 2015 at 5:48:11 AM UTC-8, Robin Tegg wrote:
>
> Hi all,
>
> I've been trying out the workflow plugin after watching the 
> pimp-your-continuous-delivery-pipeline-with-jenkins-workflow-wjax-14 
> <http://www.slideshare.net/cloudbees/pimp-your-continuous-delivery-pipeline-with-jenkins-workflow-wjax-14>
>  demo. 
> And in one of the slides (24), there is an example of a for loop that looks 
> to iterate over a list of hostnames. I've assumed that hostnames is a list
>
> def hostnames = ["192.168.0.1", "192.168.0.2"]
> for( def hostname: hostnames ) {
>     sh "ssh ${hostname} ..."
>   }
>
> I'm wondering if anyone can help with my usage of arrays/lists. I'm 
> getting the following errors when I try the above:
>
> java.io.NotSerializableException: java.util.AbstractList$Itr
>
>
> Now I understand from the docs 
> (https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md#serialization-of-local-variables)
>  that some variables can't be serialized before a "sh" step might happen, but 
> as I'm new to groovy I'm struggling to understand how the above might be 
> achieved. I've tried in a method and inline as suggested.
>
>
> The workaround I have at the moment is
>
>
> def hostnames = ["192.168.0.1", "192.168.0.2"]
> for( int i = 0; i < hostnames.size(); i++) {
>   sh "ssh ${hostnames.get(i)} ..."
> }
>
> Any pointers would be much appreciated
>
> Thanks
> Robin
>

-- 
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/9dde8b3d-04a5-4644-96a0-2930f78c4978%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to