I'm trying to loop over a var that contains multiple strings (file paths),
and then run a shell script against each one. But for some reason
everything i try loops over every single letter of the string. Here is my
code:
def call(Map config) {
node('terraform-slave') {
cleanWs()
checkout scm
stage('Plan') {
commitChangeset = sh(returnStdout: true, script: 'git diff-tree
--no-commit-id --name-only -r HEAD').trim()
}
stage('EchoToVerify') {
tfvars = commitChangeset.replaceAll("terraform.tfvars", "")
echo tfvars
}
stage('Loop') {
loop(tfvars)
}
}
}
def loop(list) {
list.each {
sh "(cd ${it}; cat terraform.tfvars)"
}
}
If you see the EchoToVerify stage, that works fine. Multiple file paths are
echo'ed, like so:
/file/to/dir1
/file/to/dir2
/file/to/dir3
But when the Loop starts, it loops against each letter.. f, i, l, e, etc....
The only way I have been able to get it work is is by doing this:
def loop(list) {
for (dir in [list]) {
sh "(cd ${it}; cat terraform.tfvars)"
}
}
However it only works when there is one value in the variable. It seems to
want to iterate over ${it} immediately, before going to the next shell
command (cat terraform.tfvars). It seems like it tries to "cd" to the next
directory immediately.
Thanks for the help!
--
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/3b411f4a-56f4-4c04-a9a4-6fde13f2239e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.