No such property: USERNAME for class: groovy.lang.Binding

I have issues with my block code - "withCredentials([usernamePassword(…it doesn’t recognize the usernameVariable and also the passwordVariable when I am using double quotes.

example jenkinsfile:

parameters {
credentials(name: 'APP_CREDS', defaultValue: 'APP_CREDS', credentialType: "Username with password", required: true, description: "Credentials")


withCredentials([usernamePassword(credentialsId: 'APP_CREDS', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
                        env.APP_USER = "${USERNAME}"
                        env.APP_PASSWORD = "${PASSWORD}"

Example error output:

Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 4d5b57c6-d3f9-4317-9a23-43cccd3a834e
groovy.lang.MissingPropertyException: No such property: USERNAME for class: groovy.lang.Binding
	at groovy.lang.Binding.getVariable(
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(
	at org.kohsuke.groovy.sandbox.impl.Checker$
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(

withCredentials already adds the items to the environment, you don’t really want to assign them to env.XXXX because they could leak. Instead you use the variables inside a shall script call or similar, by referencing the variable names you specified in the withCredentials (e.g., USERNAME and PASSWORD). If you want them to be called APP_USER and APP_PASSWORD, then you would change the usernameVariable and passwordVariable values.

1 Like