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
More on Declarative pipeline syntax
What is the minimum valid declarative pipeline?BeginnerWhat agent types exist in declarative pipelines?IntermediateWhen do you use `agent none` at the top level?IntermediateHow do nested sequential stages work and why are they useful?IntermediateList the `post` conditions and when each fires.IntermediateWhat are the most useful `when` conditions?Intermediate