简体   繁体   English

jenkins 中的 groovy 脚本失败

[英]groovy script in jenkins fails

I have a groovy script which works fine for all jenkins job but fails for one jenkin jobs.我有一个 groovy 脚本,它适用于所有 jenkins 工作,但无法用于一项 jenkin 工作。 It works fine in Jenkins scriptler but does not work when I create the job dsl in groovy.它在 Jenkins 脚本程序中运行良好,但当我在 groovy 中创建作业 dsl 时不起作用。

parameters {
activeChoiceParam('BRANCH') {
 com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
    com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class

    """)
    }
}

fails with error因错误而失败

Caused by: groovy.lang.MissingPropertyException: No such property: github_token for class: javaposse.jobdsl.dsl.helpers.parameter.ActiveChoiceGroovyScriptContext

When using triple quotes, the GString replacement still works.使用三引号时,GString 替换仍然有效。 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.所以你必须引用美元符号。 eg例如

...
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)或者使用三重单引号(如果您根本不想替换该字符串)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM