Your code uses a literal string, so your Jenkins variable will not be interpolated inside the shell command. You need to use " to interpolate the variable inside the lines inside sh . ' Just pass the literal string. Therefore, we need to make a few changes.
First, you need to change the ' to " :
for (i in [ 'a', 'b', 'c' ]) { echo i sh "echo "from shell i=$i"" }
However, now we need to avoid the " inside:
for (i in [ 'a', 'b', 'c' ]) { echo i sh "echo \"from shell i=$i\"" }
In addition, if the variable is added directly to the line, as you do above ( $i by i= ), we need to close it with some curly braces:
for (i in [ 'a', 'b', 'c' ]) { echo i sh "echo \"from shell i=${i}\"" }
This will give you the behavior you desire.
source share