Using the Pipeline plugin in Jenkins 2.x, how can I access a Groovy variable that is defined somewhere at stage- or node-level from within a sh
step?
Si
I am adding the comment from @Pedro as an answer because I think it is important.
For sh env vars we must use
sh "echo \$some_var"
In order to Pass groovy parameters into bash scripts in Jenkins pipelines - Use this post here
I would like to add another scenario to this discussion. I was using shell environment variables and groovy variables in the same script.
format='html'
for file in *.txt;
do mv -- "\$file" "\${file%.txt}.$format";
done
So here, What I have done is use \$ only for shell environment variables and use $ for groovy variables.
To use a templatable string, where variables are substituted into a string, use double quotes.
sh "echo $some_var"