Reputation: 19329
Using Jenkins Credentials I created MY_USERNAME
entry choosing the User Name and Password
type:
Now I can access this variable in Groovy script:
withCredentials([usernamePassword(
credentialsId: 'MY_USERNAME_ID',
passwordVariable: 'pwd',
usernameVariable: 'user')
]) {
sh 'echo $user'
sh "echo $pwd"
sh "echo ${user}"
echo('$pwd')
echo("$user")
echo("${pwd}")
echo user
}
All the above commands are able to get the variable value. And all of them are masking the values replacing the real characters with the asterisk, such as ***********
.
Now I need to save the real username and password values to a text file. How to save them to a file?
Upvotes: 1
Views: 453
Reputation: 27756
Credentials are only masked in the console output. This works:
withCredentials([usernamePassword(
credentialsId: 'MY_USERNAME_ID',
passwordVariable: 'pwd',
usernameVariable: 'user')
]) {
writeFile file: 'pwdfile', text: "$user:$pwd"
}
Upvotes: 3