Problems with % in a credential

Hi,

I’m trying to use a password in Jenkins credential section, but my password contains a percentage character (%). And then, for some reason, when I use this credential in a pipeline script the Jenkins remove this character and use the password without this. For example, my password is:

“blabla%blabla”

When I saw the pipeline log, I saw this:

“blablablabla”

1 Like

Hi there,

“it doesn’t work” is always hard to remote debug. Try to always include these 3 things.

  1. what did you try? (Code samples, command lines, screenshots, videos, etc)
  2. what did happen? (Error messages, description, outputs, stuff)
  3. what did you expect to happen?

Otherwise, it’s hard for us to get into your context and you’ll have to have someone who is exactly knowledgeable come along.

Hi!

I set the password credential like this, and then, when I use this credentials in my pipeline it’s happens:

Jenkins removed the character %.

I don’t think it is Jenkins that removed the ‘%’ character. I suspect that the command processor on Windows is seeing the ‘%’ as the start of a variable and is removing it.

I created a Freestyle project and enabled “Use secret text(s) or file(s)” then assigned MY_USER_NAME as the username variable and MY_PASSWORD as the password variable, using an intentionally invalid credential with a password with the value ‘50%-of-people-are-half-the-world’.

Using that credential, I had the batch command step write environment variables to a file that uses the name of that password variable.

My batch script was:

echo My password is %MY_PASSWORD%
echo My user name is %MY_USER_NAME%
set > %MY_PASSWORD%
dir

The console output hides the value of the password, but when I look in the Jenkins workspace browser for that job, it shows a file on the file system named “50%-of-people-are-half-the-world”. Jenkins passed the environment variable through to the Windows bat correctly as far as I can see.

Building on what marc says, and according to your screenshot, your using groovy variables inside your bat statement.

so assuming MY_PASSWORD=“FOO%BAR%”

bat("echo $MY_PASSWORD") will produce echo FOO%BAR% which windows will try and interpret

if you use single quotes, with %VAR%, then your shell(bat) will process it, not the output of it

bat('echo %MY_PASSWORD%') should only get interpreted once.

@halkeye

My script already use ". But It doesn’t work :pensive:

stage('Deploy Cloud'){
    withCredentials([usernamePassword(credentialsId: "cloud-credentials", usernameVariable: "USERNAME", passwordVariable: "PASSWORD")]) { 
	    bat """ "C:\\Program Files (x86)\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe" -verb:sync -source:iisApp="${destination}" -enableRule:AppOffline -dest:iisApp="${iisApplicationName}",ComputerName="${targetServerIP}",UserName="$USERNAME",Password="$PASSWORD" -allowUntrusted"""
    }
}

those are double quotes

Thats a groovy variable. Because its inside of the triple quotes, groovy will interpret it.
you want %PASSWORD% to replace it with a windows env/variable

Generally frustrating statement. What are you expecting it to do? What did it do? and in this case its implied, but what did you try

Potentially you could just single quote the one argument and windows won’t try to evaluate your %, but I don’t know if windows works that way, bash would allow it

'-dest:iisApp="${iisApplicationName}",ComputerName="${targetServerIP}",UserName="${USERNAME}",Password="${PASSWORD}"'

When I use the same command in CMD with %, it works well. But with Jenkins the problem persists.

My script:

stage('Deploy Cloud'){
    withCredentials([usernamePassword(credentialsId: "cloud-credentials", usernameVariable: "USERNAME", passwordVariable: "PASSWORD")]) { 
	    bat """ "C:\\Program Files (x86)\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe" -verb:sync -source:iisApp="${destination}" -enableRule:AppOffline -dest:iisApp="${iisApplicationName}",ComputerName="${targetServerIP}",UserName="${USERNAME}",Password="${PASSWORD}" -allowUntrusted """
    }
}   

Result:

The PASSWORD variable was interpret without % caracter.