Reputation: 1073
I builded Jenkins with parameters in my configuration:
a = a$
b = b$$
c = c$$$
d = d$$$$
e = e$e$e$e$
I builded my pipeline and it contained this possibilities how to display content of environment variables:
sh """
echo "${env.a}"
echo "\$a"
echo "${env.b}"
echo "\$b"
echo "${env.c}"
echo "\$c"
echo "${env.d}"
echo "\$d"
echo "${env.e}"
echo "\$e"
"""
It returned:
+ echo 'a$'
a$
+ echo 'a$$'
a$$
+ echo 'b$'
b$
+ echo 'b$$'
b$$
+ echo c14
c14
+ echo 'c$$$$'
c$$$$
+ echo d14
d14
+ echo 'd$$$$'
d$$$$
+ echo 'eeee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$14'
eeee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$14
+ echo 'ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$'
ee$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$e$$$$
Anyone who can explain this behaviour?
Upvotes: 2
Views: 1417
Reputation: 3095
First of all - very interesting problem. Results are... unusual :)
I couldn't reproduce 100% of your results on my Jenkins, it's probably version/platform dependent. But fortunately the most interesting parameter e
returned all that mess. So I'll focus on in.
It looks like parameters are evaluated before they are passed to environment. So each occurrence of $e
is replaced by current value of e
variable (which is e$e$e$e$
so far). So, we have e
then three times $e
replaced by e$e$e$e$
and finally $
. The result is: e e$e$e$e$ e$e$e$e$ e$e$e$e$ $
(spaces added for readability). And this is value stored in environment. You can see it printed by your last echo
(but with every $
replaced by $$
).
The longest output (echo "${env.e}"
) doesn't do anything new - it just takes ee$e$e$e$e$e$e$e$e$e$e$e$$
and evaluates it one more time, replacing every occurrence of $e
by ee$e$e$e$e$e$e$e$e$e$e$e$$
. And finally, replaces every $
by $$
when printing :)
Upvotes: 1