I am using bash script inside Groovy in the Jenkins pipeline. Jenkins job is parameterized and using a password parameter option named "PASSWORD". The issue is when password contains "$" sign, then it is getting escaped in the bash script. For example: Actual password inputed is "ppa$$worddd" but in the bash script $PASSWORD value is "ppa$worddd". As we could see one "$" is removed. Please look at the code below. Please help
def password = params.get('PASSWORD')
stage('execute') {
steps {
script {
println password // - Here value is "ppa$$worddd" as expected
withCredentials([string(credentialsId: 'ID', variable: 'C_ID'),string(credentialsId: 'SE', variable: 'C_SE')]) {
if (!starsValue.isEmpty()) {
sh '''
cd Scripts
echo $PASSWORD // - Here value is "ppa$worddd" .As seen one "$" is removed
'''
}
}
}
}
}
Under some very specific circumstances Jenkins does variable expansion. Syntax is arbitrary, but somewhat documented here. I think at some point they wanted to ignore $$
combinations, but then some random patch "improved" on that idea and now we have what we have.
There is no way to disable this variable expansion, you can only avoid it by doing seemingly equivalent things that for some reason bypass it:
withEnv(["PASSWORD=${params.PASSWORD}"]){
sh 'echo $PASSWORD'
}