Using Jenkins 2.440.2.
I am using credentials but for some reason I have to urlencode one of the credentials (since it’s used together with sh 'curl ...'
) but it is also used in a “plain” version.
Unfortunately, Jenkins is leaking the encoded password when it differs from the credential.
withCredentials([usernamePassword(credentialsId: 'xyz', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
script {
String duplicate_password = env.PASSWORD
String encoded_password = java.net.URLEncoder.encode(env.PASSWORD, "UTF-8")
echo "credential password is ${env.PASSWORD}"
echo "duplicate_password is ${duplicate_password}"
echo "encoded_password is ${encoded_password}"
}
}
The output of this is:
14:45:20 Warning: A secret was passed to "echo" using Groovy String interpolation, which is insecure.
14:45:20 Affected argument(s) used the following variable(s): [PASSWORD]
14:45:20 See https://****.io/redirect/groovy-string-interpolation for details.
14:45:20 credential password is ****
14:45:20 [Pipeline] echo
14:45:20 Warning: A secret was passed to "echo" using Groovy String interpolation, which is insecure.
14:45:20 Affected argument(s) used the following variable(s): [PASSWORD]
14:45:20 See https://****.io/redirect/groovy-string-interpolation for details.
14:45:20 duplicate_password is ****
14:45:20 [Pipeline] echo
14:45:20 encoded_password is REDACTED
Is there a way or plugin to be able to create a local variable which is masked in echo
and sh
(here: output and blue ocean label, not the actual command executed)?
At the moment I can only see two options, both of which have their disadvantages:
- Have two credentials: one urlencoded, the other one as plaintext
- Ensure the credential requires no urlencoding
Both options have the disadvantage that they can easily be forgotten when changing passwords and the like. It would therefore be best if there were a way to do this programmatically.
Does anybody know of such an option?
Thank you!