I have a list foo = ['tea',''sugar','milk']
and col = ['black','white','pink']
what I am trying to do is nested loop
def foo = ['tea','sugar','milk']
def col = ['black','white','pink']
[foo, col].transpose().each { x, y ->
sh """aws deploy push --application-name "${x}" --source "${y}" """
}
Desired Result
--application-name "tea" --source "black"
--application-name "sugar" --source "white"
--application-name "milk" --source "pink"
the result I am getting
[Pipeline] script
[Pipeline] {
[Pipeline] echo
--application-name "[tea, black]" --source "null"
[Pipeline] echo
--application-name "[sugar, white]" --source "null"
[Pipeline] echo
--application-name "[milk, pink]" --source "null"
[Pipeline] }
[Pipeline] // script
[Pipeline] }
I want the list items in foo and col to be injected one by one to the above shell script Is there a way where we can pass both list items at once to the above shell script
Ref Nested `each` loops in Groovy
Can we do something like (foo,col).each
or maybe using for loop for(x in foo && y in col)
Ref my Jenkinsfile
pipeline {
agent any
stages {
stage('hello'){
steps{
script{
def foo = ['tea','sugar','milk']
def col = ['black','white','pink']
[foo, col].transpose().each { x, y ->
sh """aws deploy push --application-name "${x}" --source "${y}" """
//echo """--application-name \"${x}\" --source \"${y}\" """
}
}
}
}
} }
I believe transpose is the method you are after, to pair up the two lists, then you can iterate through the result:
UPDATE:
This is what I was aiming at. Note that some of the parameters are removed for brevity
results