Hi
I have a groovy script as my Jenkins pipeline script, which looks something like
node("nodeName") {
. . . (some groovy code)
sh """
......
< This section of the shell script calculates the value of the variable varName, example being BUILD_NUMBER >
......
echo "${env.BUILD_ID}" # This prints expected output. Example : 51
export varName="env.BUILD_NUMBER"
echo "${"\$varName"}" # This prints the output as env.BUILD_NUMBER and not 51
"""
...
}
In the above example, I had hard coded value of varName as env.BUILD_NUMBER. In my actual script, value of varName will be calculated during execution.
In bash script, this result can be achieved as follows:
#!/bin/bash
variable_1="abc"
variable_2=variable_1
echo "${!variable_2}"
Exclamation mark (!) doesn't work in shell script inside Jenkins pipeline
Can someone please explain, how to address my requirement ?
Thank you
Jason
I am sorry that by mistake, have posted my query here. Please ignore.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.