# Problems with % in a credential

**URL:** <https://community.jenkins.io/t/problems-with-in-a-credential/1357>\
**Category:** Using Jenkins\
**Tags:** question\
**Created:** [January 27, 2022, 3:47pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357 "2022-01-27T15:47:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![emauricio\_tasken](https://avatars.discourse-cdn.com/v4/letter/e/4da419/32.png) [@emauricio\_tasken](https://community.jenkins.io/u/emauricio_tasken)\
**Post date:** [January 27, 2022, 3:47pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357/1 "2022-01-27T15:47:41Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [January 27, 2022, 5:47pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357/2 "2022-01-27T17:47:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![emauricio\_tasken](https://avatars.discourse-cdn.com/v4/letter/e/4da419/32.png) [@emauricio\_tasken](https://community.jenkins.io/u/emauricio_tasken)\
**Post date:** [January 27, 2022, 8:08pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357/3 "2022-01-27T20:08:25Z")

</div>

Hi!

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

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/1X/544e4ae1351775416a0982e4a14d5eb2a96af15c.png)

Jenkins removed the character %.

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [January 27, 2022, 9:18pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357/4 "2022-01-27T21:18:15Z")

</div>

> [@emauricio\_tasken](#):
>
> 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:

```plaintext
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.

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [January 27, 2022, 10:29pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357/5 "2022-01-27T22:29:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![emauricio\_tasken](https://avatars.discourse-cdn.com/v4/letter/e/4da419/32.png) [@emauricio\_tasken](https://community.jenkins.io/u/emauricio_tasken)\
**Post date:** [January 28, 2022, 2:12pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357/6 "2022-01-28T14:12:29Z")

</div>

@halkeye

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

```
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"""
    }
}
```

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [January 28, 2022, 5:37pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357/7 "2022-01-28T17:37:39Z")

</div>

> [@emauricio\_tasken](#):
>
> `bat """`

those are double quotes

> [@emauricio\_tasken](#):
>
> `Password="$PASSWORD"`

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

> [@emauricio\_tasken](#):
>
> But It doesn’t work

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

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [January 28, 2022, 6:02pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357/8 "2022-01-28T18:02:12Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![emauricio\_tasken](https://avatars.discourse-cdn.com/v4/letter/e/4da419/32.png) [@emauricio\_tasken](https://community.jenkins.io/u/emauricio_tasken)\
**Post date:** [February 3, 2022, 4:45pm UTC](https://community.jenkins.io/t/problems-with-in-a-credential/1357/9 "2022-02-03T16:45:34Z")

</div>

> [@halkeye](#):
>
> `erName="${targetServe`

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.
