简体   繁体   中英

groovy script in jenkins fails

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

    """)
    }
}

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. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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