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}" """
}
}
}
}


}
}










share|improve this question
























  • 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















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}" """
}
}
}
}


}
}










share|improve this question
























  • 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













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}" """
}
}
}
}


}
}










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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"





share|improve this answer























  • 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










  • And sh """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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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"





share|improve this answer























  • 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










  • And sh """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















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"





share|improve this answer























  • 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










  • And sh """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













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"





share|improve this answer














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"






share|improve this answer














share|improve this answer



share|improve this answer








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










  • And sh """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












  • @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










  • And sh """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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)