cloudbud
cloudbud

Reputation: 3288

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

Upvotes: 1

Views: 644

Answers (1)

cfrick
cfrick

Reputation: 37063

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)

Upvotes: 2

Related Questions