Jenkins中的常规脚本失败 [英] groovy script in jenkins fails
问题描述
我有一个时髦的脚本,该脚本对于所有詹金斯工作都可以正常工作,但对于一个詹金斯工作却无法完成. 它在Jenkins脚本编写器中工作正常,但是在groovy中创建作业dsl时不起作用.
I have a groovy script which works fine for all jenkins job but fails for one jenkin jobs. It works fine in Jenkins scriptler but does not work when I create the job dsl in groovy.
parameters {
activeChoiceParam('BRANCH') {
com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class
""")
}
}
发生错误
Caused by: groovy.lang.MissingPropertyException: No such property: github_token for class: javaposse.jobdsl.dsl.helpers.parameter.ActiveChoiceGroovyScriptContext
推荐答案
使用三引号时,GString替换仍然有效.因此,在这样的字符串中写入${...}
将立即替换该变量.但是您希望将其延迟到脚本运行之前.因此,您必须引用美元符号.例如
When using triple quotes, the GString replacement still works. So writing ${...}
in such a string will replace the variable at once. But you want to delay this until the script is run. So you have to quote the dollar sign. e.g.
...
inputFile.write("curl ... -H 'Authorization: token \${github_token.password}'...")
...
或使用三重单引号(如果您根本不希望对该字符串进行任何替换)
Or use triple single quotes (if you don't want any replacements for that string at all)
这篇关于Jenkins中的常规脚本失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!