【发布时间】:2019-05-17 09:18:30
【问题描述】:
我有一个如下的詹金斯管道。我需要 aws 的输出,它返回要拆分的多个项目并用作 for 循环中的单个项目,可用于执行另一个操作
我试过def ASG_GROUP_NAME toString(),因为它似乎没有作为完整的字符串返回,但没有运气
def ASG_GROUP_NAME = sh (script: """
aws autoscaling describe-auto-scaling-groups --region ${AWS_REGION} --query "AutoScalingGroups[? Tags[? Key=='Environment' && Value=='${ENVIRONMENT}']] | [? Tags[? Key=='Service' && Value =='${SERVICE_NAME}']]".AutoScalingGroupName --output text
""", returnStdout: true)
sh "echo ${ASG_GROUP_NAME}"
def texts = ASG_GROUP_NAME.split(' ')
for (txt in texts) {
sh "echo ${txt}"
}
预期:
09:52:45 [test] Running shell script
09:52:45 + echo test1.var1.eu-20190414121923517200000001
09:52:45 test1.var1.eu-20190414121923517200000001
[Pipeline] sh
09:52:45 [test] Running shell script
09:52:45 + echo test2.var2.ue1-20190414121925623400000002
09:52:45 test2.var2.ue1-20190414121925623400000002
[Pipeline] sh
09:52:45 [test] Running shell script
09:52:45 + echo test3.var3.ue1-20190414121926583500000003
09:52:45 test3.var3.ue1-20190414121926583500000003
[Pipeline] }
[Pipeline] // script
实际:
09:52:45 test1.var1.eu-20190414121923517200000001 test2.var2.eu-20190414121923517200000001 test3.var3.eu-20190414121923517200000001
【问题讨论】:
-
你应该得到至少 2 个回声,对吧?
-
对.. 应该有 1 个或多个回声返回
标签: amazon-web-services for-loop groovy jenkins-pipeline