带有字符串变量问题的 Jenkinsfile
Jenkinsfile with string variable issue
我有一个 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]}"
我有一个 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]}"