The example below works:
void updateApplicationVersionMaven(String version) { sh "mvn -B versions:set -DnewVersion=$version" }
And the full pipeline script (tested on Jenkins 2.7.3):
node { stage('test') { def testVar='foo' sh "echo $testVar" } }
EDIT (after comments): Ah, checked a few more and was able to reproduce the problem. This is because you are using a script with. /opt/setup.sh. This affects the shell environment, in which case it breaks the injection of the Jenkins variable. Interesting.
EDIT2 (after comments): I believe this is a problem with the default shell used (either Jenkins or OS). I could reproduce the problem from the comments and was able to get around it, explicitly using bash as a shell:
def testVar='foo3' sh "bash -c \". /var/jenkins_home/test.sh $testVar && echo \$ARCH\""
The last echo now displays the contents of testVar, which was passed as a script argument and then set to script as an environment variable.
source share