I’m facing an issue with Jenkins where a secret containing special characters (specifically $ and =) gets truncated when used in a shell script. Here are the details:
I have a secret in Jenkins that stores the following string:
111111-d032-40bd-b87d1153a9430e92$fmN1pdifFkespherhHjIO70KjIzZfqjevCGY3kAbxjU=
I am using this secret in my Jenkins pipeline like this:
string(credentialsId: "${env.PREFIX}-mes-client-secret", variable: 'MYSECRET'),
sh "echo MES_CLIENT_SECRET='$MES_CLIENT_SECRET' >> ${env.ENV_FILE}"
However, when I check the output in my .env file, the string gets truncated at the $ and replaced with =
MYSECRET='111111-d032-40bd-b87d1153a9430e92=fmN1pdifFkespherhHjIO70KjIzZfqjevCGY3kAbxjU='
I suspect Jenkins is misinterpreting the $ as a variable substitution. How can I ensure the secret is correctly passed into my shell script without truncation or alteration?
What I’ve Tried:
Changing double quotes to single quotes around the credentialsId, but this doesn’t seem to work as expected.
Looking for ways to escape the $ in the secret, but I haven’t found a solution that works.
Environment:
Jenkins version: latest
Pipeline type: Declarative
Any help or suggestions would be greatly appreciated!