I want to use a variable which I am using inside of my Jenkinsfile
script, and then pass its value into a shell script execution (either as an environment variable or command line parameter).
But the following Jenkinsfile
:
for (i in [ 'a', 'b', 'c' ]) {
echo i
sh 'echo "from shell i=$i"'
}
Gives the output:
a
from shell i=
b
from shell i=
c
from shell i=
Desired output is something like:
a
from shell i=a
b
from shell i=b
c
from shell i=c
Any idea how to pass the value of i
to the shell scipt?
Edit: Based upon Matt's answer, I now use this solution:
for (i in [ 'a', 'b', 'c' ]) {
echo i
sh "i=${i}; " + 'echo "from shell i=$i"'
}
The advantage is, that I don't need to escape the "
in the shell script.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…