【发布时间】:2019-10-03 20:50:14
【问题描述】:
我正在创建一个 jenkins 管道,它有一个字符串作为 1 个或多个项目的变量
text="test1.var1.eu-20190414121923517200000001 test2.var2.ue1-20190414121925623400000002 test3.var3.ue1-20190414121926583500000003"
我基本上想进入一个循环并为每个项目运行一个动作。例如依次回显每个。 echo 将查看字符串并在 for 循环中返回每个项目,其中有 1 个或多个结果
预期结果:
test1.var1.eu-20190414121923517200000001
test2.var2.ue1-20190414121925623400000002
test3.var3.ue1-20190414121926583500000003
我尝试了一些方法,包括添加 sh 来运行 for 循环
#!/usr/local/bin/groovy
pipeline {
parameters {
choice(choices: "1\n2\n3", description: 'The length of time for the environment to remain up', name: 'hours')
}
stages {
stage('get and update hours') {
steps {
script {
env.text="test1.var1.eu-20190414121923517200000001 test2.var2.ue1-20190414121925623400000002 test3.var3.ue1-20190414121926583500000003"
sh "echo ${text}"
sh "for value in ${text}; do echo $value; done"
}
}
}
}
}
预期结果
test1.var1.eu-20190414121923517200000001
test2.var2.ue1-20190414121925623400000002
test3.var3.ue1-20190414121926583500000003
实际结果:
[管道] 管道结束 [Office365connector] 没有要通知的 webhook groovy.lang.MissingPropertyException:没有这样的属性:类的值:> groovy.lang.Binding 在 groovy.lang.Binding.getVariable(Binding.java:63) 在 org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:264) 在 org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288) 在 org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292) 在 org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
【问题讨论】:
-
你现在得到了什么结果?
-
15:56:29 [test] Running shell script 15:56:29 + echo test1.var1.eu-20190414121923517200000001 test2.var2.ue1-20190414121925623400000002 test3.var3.ue1-20190414121926583500000003 15:56:29 test1.var1.eu-20190414121923517200000001 test2.var2.ue1-20190414121925623400000002 test3.var3.ue1-20190414121926583500000003 [Pipeline] } [Pipeline] // timestamps [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline [Office365connector] No webhooks to notify groovy.lang.MissingPropertyException: No such property: value for class: -
我也在下面尝试过同样的错误:
-
` script { env.text="test1.var1.eu-20190414121923517200000001 test2.var2.ue1-20190414121925623400000002 test3.var3.ue1-20190414121926583500000003 "为 ${text} 中的值;做 echo $value;完成",returnStdout: true).trim() } `
标签: shell for-loop jenkins split jenkins-pipeline