Script pipeline To read an environment variable whose name you know, use env.NAME
To read an environment variable whose name is not known until runtime, use env.getProperty(name) .
For example, the value from the YAML configuration file represents the name of an environment variable:
config.yaml (in the workspace)
myconfig: key: JOB_DISPLAY_URL
Jenkinsfile
node { println("Running job ${env.JOB_NAME}") def config = readYaml(file:'config.yaml') def value = env.getProperty(config.myconfig.key) println("Value of property ${config.myconfig.key} is ${value}") }
source share