passing items in two lists simultaneoulsy in each loop Jenkinsfile
up vote
1
down vote
favorite
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}" """
}
}
}
}
}
}
jenkins groovy jenkins-pipeline jenkins-groovy
add a comment |
up vote
1
down vote
favorite
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}" """
}
}
}
}
}
}
jenkins groovy jenkins-pipeline jenkins-groovy
For simplicity pupose I am using echo instead of sh in jenkinsfile because if we use sh we get command not found
– startprogramming
Nov 9 at 15:21
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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}" """
}
}
}
}
}
}
jenkins groovy jenkins-pipeline jenkins-groovy
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}" """
}
}
}
}
}
}
jenkins groovy jenkins-pipeline jenkins-groovy
jenkins groovy jenkins-pipeline jenkins-groovy
edited Nov 9 at 15:28
asked Nov 8 at 22:32
startprogramming
459
459
For simplicity pupose I am using echo instead of sh in jenkinsfile because if we use sh we get command not found
– startprogramming
Nov 9 at 15:21
add a comment |
For simplicity pupose I am using echo instead of sh in jenkinsfile because if we use sh we get command not found
– startprogramming
Nov 9 at 15:21
For simplicity pupose I am using echo instead of sh in jenkinsfile because if we use sh we get command not found
– startprogramming
Nov 9 at 15:21
For simplicity pupose I am using echo instead of sh in jenkinsfile because if we use sh we get command not found
– startprogramming
Nov 9 at 15:21
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I believe transpose is the method you are after, to pair up the two lists, then you can iterate through the result:
[foo, col].transpose().each { x, y ->
...
}
UPDATE:
This is what I was aiming at. Note that some of the parameters are removed for brevity
def foo = ['tea','sugar','milk']
def col = ['black','white','pink']
[foo, col].transpose().each { x, y ->
println """--application-name "${x}" --source "${y}" """
}
results
--application-name "tea" --source "black"
--application-name "sugar" --source "white"
--application-name "milk" --source "pink"
Thansk for the quick reply @tim_yates but unfortunately the result I am getting is--application-name '[tea, black]'
and for--source null
I need to get--application-name tea
and--source black
and for the next loop i need to get--application-name suagr
and--source white
and so on
– startprogramming
Nov 8 at 23:11
@startprogramming Please check the update in the answer.
– dmahapatro
Nov 9 at 2:40
Thanks @dmahapatro this works fine I have checked in tutoriaslpoint but when you execute in Jenkins its still the same as my previous comment and I want to execute in shell script not just echo or println
– startprogramming
Nov 9 at 15:30
Andsh """aws deploy push --application-name "$x" --source "$y" """
doesn't work?
– tim_yates
Nov 9 at 15:37
1
Try:[foo, col].transpose().each { x -> sh """aws deploy push --application-name "${x[0]}" --source "${x[1]}" """ }
– tim_yates
Nov 9 at 19:01
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I believe transpose is the method you are after, to pair up the two lists, then you can iterate through the result:
[foo, col].transpose().each { x, y ->
...
}
UPDATE:
This is what I was aiming at. Note that some of the parameters are removed for brevity
def foo = ['tea','sugar','milk']
def col = ['black','white','pink']
[foo, col].transpose().each { x, y ->
println """--application-name "${x}" --source "${y}" """
}
results
--application-name "tea" --source "black"
--application-name "sugar" --source "white"
--application-name "milk" --source "pink"
Thansk for the quick reply @tim_yates but unfortunately the result I am getting is--application-name '[tea, black]'
and for--source null
I need to get--application-name tea
and--source black
and for the next loop i need to get--application-name suagr
and--source white
and so on
– startprogramming
Nov 8 at 23:11
@startprogramming Please check the update in the answer.
– dmahapatro
Nov 9 at 2:40
Thanks @dmahapatro this works fine I have checked in tutoriaslpoint but when you execute in Jenkins its still the same as my previous comment and I want to execute in shell script not just echo or println
– startprogramming
Nov 9 at 15:30
Andsh """aws deploy push --application-name "$x" --source "$y" """
doesn't work?
– tim_yates
Nov 9 at 15:37
1
Try:[foo, col].transpose().each { x -> sh """aws deploy push --application-name "${x[0]}" --source "${x[1]}" """ }
– tim_yates
Nov 9 at 19:01
|
show 2 more comments
up vote
1
down vote
accepted
I believe transpose is the method you are after, to pair up the two lists, then you can iterate through the result:
[foo, col].transpose().each { x, y ->
...
}
UPDATE:
This is what I was aiming at. Note that some of the parameters are removed for brevity
def foo = ['tea','sugar','milk']
def col = ['black','white','pink']
[foo, col].transpose().each { x, y ->
println """--application-name "${x}" --source "${y}" """
}
results
--application-name "tea" --source "black"
--application-name "sugar" --source "white"
--application-name "milk" --source "pink"
Thansk for the quick reply @tim_yates but unfortunately the result I am getting is--application-name '[tea, black]'
and for--source null
I need to get--application-name tea
and--source black
and for the next loop i need to get--application-name suagr
and--source white
and so on
– startprogramming
Nov 8 at 23:11
@startprogramming Please check the update in the answer.
– dmahapatro
Nov 9 at 2:40
Thanks @dmahapatro this works fine I have checked in tutoriaslpoint but when you execute in Jenkins its still the same as my previous comment and I want to execute in shell script not just echo or println
– startprogramming
Nov 9 at 15:30
Andsh """aws deploy push --application-name "$x" --source "$y" """
doesn't work?
– tim_yates
Nov 9 at 15:37
1
Try:[foo, col].transpose().each { x -> sh """aws deploy push --application-name "${x[0]}" --source "${x[1]}" """ }
– tim_yates
Nov 9 at 19:01
|
show 2 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I believe transpose is the method you are after, to pair up the two lists, then you can iterate through the result:
[foo, col].transpose().each { x, y ->
...
}
UPDATE:
This is what I was aiming at. Note that some of the parameters are removed for brevity
def foo = ['tea','sugar','milk']
def col = ['black','white','pink']
[foo, col].transpose().each { x, y ->
println """--application-name "${x}" --source "${y}" """
}
results
--application-name "tea" --source "black"
--application-name "sugar" --source "white"
--application-name "milk" --source "pink"
I believe transpose is the method you are after, to pair up the two lists, then you can iterate through the result:
[foo, col].transpose().each { x, y ->
...
}
UPDATE:
This is what I was aiming at. Note that some of the parameters are removed for brevity
def foo = ['tea','sugar','milk']
def col = ['black','white','pink']
[foo, col].transpose().each { x, y ->
println """--application-name "${x}" --source "${y}" """
}
results
--application-name "tea" --source "black"
--application-name "sugar" --source "white"
--application-name "milk" --source "pink"
edited Nov 9 at 2:39
dmahapatro
41.3k75793
41.3k75793
answered Nov 8 at 22:37
tim_yates
130k20250267
130k20250267
Thansk for the quick reply @tim_yates but unfortunately the result I am getting is--application-name '[tea, black]'
and for--source null
I need to get--application-name tea
and--source black
and for the next loop i need to get--application-name suagr
and--source white
and so on
– startprogramming
Nov 8 at 23:11
@startprogramming Please check the update in the answer.
– dmahapatro
Nov 9 at 2:40
Thanks @dmahapatro this works fine I have checked in tutoriaslpoint but when you execute in Jenkins its still the same as my previous comment and I want to execute in shell script not just echo or println
– startprogramming
Nov 9 at 15:30
Andsh """aws deploy push --application-name "$x" --source "$y" """
doesn't work?
– tim_yates
Nov 9 at 15:37
1
Try:[foo, col].transpose().each { x -> sh """aws deploy push --application-name "${x[0]}" --source "${x[1]}" """ }
– tim_yates
Nov 9 at 19:01
|
show 2 more comments
Thansk for the quick reply @tim_yates but unfortunately the result I am getting is--application-name '[tea, black]'
and for--source null
I need to get--application-name tea
and--source black
and for the next loop i need to get--application-name suagr
and--source white
and so on
– startprogramming
Nov 8 at 23:11
@startprogramming Please check the update in the answer.
– dmahapatro
Nov 9 at 2:40
Thanks @dmahapatro this works fine I have checked in tutoriaslpoint but when you execute in Jenkins its still the same as my previous comment and I want to execute in shell script not just echo or println
– startprogramming
Nov 9 at 15:30
Andsh """aws deploy push --application-name "$x" --source "$y" """
doesn't work?
– tim_yates
Nov 9 at 15:37
1
Try:[foo, col].transpose().each { x -> sh """aws deploy push --application-name "${x[0]}" --source "${x[1]}" """ }
– tim_yates
Nov 9 at 19:01
Thansk for the quick reply @tim_yates but unfortunately the result I am getting is
--application-name '[tea, black]'
and for --source null
I need to get --application-name tea
and --source black
and for the next loop i need to get --application-name suagr
and --source white
and so on– startprogramming
Nov 8 at 23:11
Thansk for the quick reply @tim_yates but unfortunately the result I am getting is
--application-name '[tea, black]'
and for --source null
I need to get --application-name tea
and --source black
and for the next loop i need to get --application-name suagr
and --source white
and so on– startprogramming
Nov 8 at 23:11
@startprogramming Please check the update in the answer.
– dmahapatro
Nov 9 at 2:40
@startprogramming Please check the update in the answer.
– dmahapatro
Nov 9 at 2:40
Thanks @dmahapatro this works fine I have checked in tutoriaslpoint but when you execute in Jenkins its still the same as my previous comment and I want to execute in shell script not just echo or println
– startprogramming
Nov 9 at 15:30
Thanks @dmahapatro this works fine I have checked in tutoriaslpoint but when you execute in Jenkins its still the same as my previous comment and I want to execute in shell script not just echo or println
– startprogramming
Nov 9 at 15:30
And
sh """aws deploy push --application-name "$x" --source "$y" """
doesn't work?– tim_yates
Nov 9 at 15:37
And
sh """aws deploy push --application-name "$x" --source "$y" """
doesn't work?– tim_yates
Nov 9 at 15:37
1
1
Try:
[foo, col].transpose().each { x -> sh """aws deploy push --application-name "${x[0]}" --source "${x[1]}" """ }
– tim_yates
Nov 9 at 19:01
Try:
[foo, col].transpose().each { x -> sh """aws deploy push --application-name "${x[0]}" --source "${x[1]}" """ }
– tim_yates
Nov 9 at 19:01
|
show 2 more comments
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217148%2fpassing-items-in-two-lists-simultaneoulsy-in-each-loop-jenkinsfile%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
For simplicity pupose I am using echo instead of sh in jenkinsfile because if we use sh we get command not found
– startprogramming
Nov 9 at 15:21