How do I invoke Global environment variables in Jenkinsfile?
For example, if I have a variable -
name:credentialsId
value:xxxx-xxxx-xxxxx-xxxxxxxxx
How do I use it in the groovy script?
I tried ${credentialsId}, but it didn't work. It will just give error:
java.lang.NoSuchMethodError: No such DSL method '$' found among steps [ArtifactoryGradleBuild, ........
In a Jenkinsfile, you have the "Working with the Environment" which mentions:
The syntax is
${env.xxx}as in:See also "Managing the Environment".
See "Setting environment variables"
If you want to initialize an environment variable with the value of another environment variable in a Jenkinsfile, you can use the
envobject to reference the existing variable.Here is an example:
In this example,
NEW_VARis a new environment variable that gets its value fromOLD_VAR, an existing environment variable.The
echostep then prints the value ofNEW_VARto the console.