Reputation: 45
I am currently facing an issue, where I have to use parameters and credentials in the same shell string, which is causing me a lot of trouble.
When handling passwords in Jenkins the documentation emphasizes the use of single quotes to avoid the interpolation of sensitive variables:
Single quote example:
However, using single quotes will result in my parameters not being interpolated as showed in the below picture:
Thus, I can't find a solution which allows my to have both, and as I see it, this leaves me with one of the following options:
Do someone know if it is possible to have both in the same string or know some sort of workaround?
Upvotes: 2
Views: 2512
Reputation: 11946
I don't like escaping, so I use a local variable for my credentials:
withCredentials([usernamePassword(
credentialsId: 'vcs_manage',
passwordVariable: 'SECRET',
usernameVariable: 'USERNAME')]
) {
// Single quotes only used when necessary.
def secret = '$USERNAME:$SECRET'
// Can interpolate it with other vars.
sh("curl -u ${secret} ${url}")
}
Generally my secret
var has both user name and password together in whatever format is necessary.
Upvotes: 0
Reputation: 1096
You can use double quotes, but escape the $
for the secret variables like this:
sh("curl -u \$USERNAME:\$PASSWORD ${url}")
You can also use single quotes:
sh('curl -u $USERNAME:$PASSWORD ' + url)
You can use it with withCredentials()
.
Upvotes: 2