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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.