Interview Prep/Jenkins/Declarative pipeline syntax

Why must secrets be used with single quotes in `sh`?

IntermediateConceptDeclarative pipeline syntax
Answer

With double quotes Groovy interpolates the secret into the command string before it reaches the shell, so the plain value is passed as the script argument, may appear in ps on the agent and in the step's arguments in the build record. Jenkins warns: A secret was passed to "sh" using Groovy String interpolation, which is insecure.

sh "curl -u $NX_USER:$NX_PASS ..."   // bad: Groovy interpolation
sh 'curl -u "$NX_USER:$NX_PASS" ...' // good: shell expands env vars
All Jenkins questions Roadmap: Jenkins

More on Declarative pipeline syntax