Jenkins管道从AWS到for循环的输出 [英] Jenkins pipeline Output from aws to for loop

查看:209
本文介绍了Jenkins管道从AWS到for循环的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个詹金斯管道,如下所示.我需要aws的输出,该输出返回要拆分的多个项目并在for循环中用作单独的项目,可用于执行其他操作

I have a jenkins pipeline as below. I need the output from aws which returns multiple items to be split and used as individual items in a for loop which can be used to perform another action

我尝试了def ASG_GROUP_NAME toString(),因为它似乎没有以完整的字符串形式返回,但是没有运气

i have tried def ASG_GROUP_NAME toString() as it seems it's not returning as a full string but with no luck

        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

推荐答案

只是一个想法,但这可能有用,似乎您不需要在groovy中使用分隔符来分隔空白

Just a thought but this might work, seems that you don't need delimiter in groovy for whitespace

def texts = ASG_GROUP_NAME.split()
for (txt in texts) {
  sh "echo ${txt}"
}

这篇关于Jenkins管道从AWS到for循环的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆