我刚开始用Jenkins编写管道,似乎无法解决这个问题。我希望使用2个静态列表,并将第二个列表项附加到第一个列表项上。大多数情况下,我已经成功地做到了这一点,但我似乎无法找到一种方法来删除第二个列表项中的括号。最终,我将把编译部分分解为一个单独的库。
提前感谢所有能提供帮助的人。
我的代码:
def food = ["eggs","chips"]
def drink =["water","juice","cola"]
def meal = []
for (String fd : food){
[drink].transpose().each {drinks ->
meal.add("Food: ${fd}, Drinks: ${drinks}")}
}
pipeline {
agent any
stages {
stage('Results') {
steps {
echo 'Results'
echo "${meal}"
}
}
}
}
结果(截短)
Results
[Pipeline] echo
[Food: eggs, Drinks: [water], Food: eggs, Drinks: [juice], Food: eggs, Drinks: [cola], Food: chips, Drinks: [water], Food: chips, Drinks: [juice], Food: chips, Drinks: [cola]]
[Pipeline] }
正如你可以看到的结果,我有我需要的,除了不能删除括号
1条答案
按热度按时间4uqofj5v1#
不要使用转置,而是使用更简单的方法如何?