groovy - 带有字符串变量问题的Jenkinsfile
问题描述
我有一个Jenkinsfile
来自输入文件的端口解析列表,
pipeline {
parameters {
string(defaultValue: '4000', name: 'Port', trim: true)
}
stage('Test') {
steps {
script {
echo 'Testing..'
script {
def data = readFile(file: 'list.txt')
println(data)
def Port = ""
data.eachLine { line ->
def arr = line.tokenize('\t')
println "port: ${arr[0]}}" # Prints values
println "port: arr[0]" # Prints name of Varible
build quietPeriod: 2,
job: 'Downstream_Jenkinsfile_Job',
parameters: [string(name: 'Port', value: ${arr[0]})] # <- ERROR HERE
}
}
}
}
}
}
该行parameters: [string(name: 'Port', value: ${arr[0]})]
给出错误
[Pipeline] End of Pipeline
java.lang.NoSuchMethodError: No such DSL method '$' found among steps [archive,
...
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
我试过:
parameters: [string(name: 'Port', value: ${arr[0]}]
parameters: [string(name: 'Port', value: arr[0]]
是什么导致了这个问题?我打字,没有运气。谢谢
解决方案
它一定要是
build quietPeriod: 2,
job: 'Downstream_Jenkinsfile_Job',
parameters: [string(name: 'Port', value: "${arr[0]}")]
$
如果在您的示例中""
和您的示例中您留下了参数值,则管道可以插入该值,${arr[0]}
但它必须像"${arr[0]}"
推荐阅读
- django - django-keycloak | 将用户名设置为 Keycloak 用户名(而不是 Keycloak ID)
- javascript - 未捕获的类型错误:无法读取未定义的属性“setCrossOrigin”
- excel - Power Query 中的 Excel 自定义函数
- flutter - 如何使小部件像按钮一样短暂改变颜色
- firebase - 第一个孩子的价值的Firebase规则
- c - 在C中递归删除单个链接列表中具有多个字段的节点
- php - 您可以通过引用将变量插入到字符串中吗?
- java - JPMS:--add-opens 不适用于 java.lang.reflect.InaccessibleObjectException
- highcharts - 将鼠标捕捉到 X 和 Y 轴
- php - 如何在 PHP 中正确编写用户定义函数?