How to set variables in a multi-line shell script within Jenkins Groovy?
You need to change to triple single quotes '''
or escape the dollar \$
Then you'll skip the groovy templating which is what's giving you this issue
I'm just putting a '\' on the end of line
sh script: """\ foo='bar' \ echo $foo \""", returnStdout: true
This statement works on my script.