def x = ['a', 'b', 'c']
println x
x.each { println it }
[Test-Groovy2] $ groovy /var/lib/jenkins/workspace/Test-Groovy2/hudson3825239812036801886.groovy [a, b, c] a b c Finished: SUCCESS
[Pipeline] echo [a, b, c] [Pipeline] echo a [Pipeline] End of Pipeline Finished: SUCCESS
--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ca2dd238-550f-46a0-8f56-1bc167402eb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
pipeline {
agent any
stages {
stage('loop') {
steps {
script {
def x = ['a', 'b', 'c']
println x
for(String item: x) {
println item
}
}
}
}
}
}
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/de886784-ca86-4872-a310-0924a7a25d9c%40googlegroups.com.
I just did it this morning, doesn't work.
You have to instead do:
for(int i = 0; i < list.size(); i++) { def elem = list[i]; ... }