Variable indirection in a pipeline?

16 views
Skip to first unread message

zil...@gmail.com

unread,
Feb 22, 2021, 9:25:50 PM2/22/21
to Jenkins Users

In my Jenkins system configuration page, I have 3 variables defined, namely, sandbox_deployedstaging_deployed, and production_deployed. In my pipeline, I want to access one of these variables, based on a pipeline property, BUILD_ENV, defined in the job's configuration page. IOW, in my job's configuration page I have

BUILD_ENV=sandbox

How can I write pipeline code that does

println "$env.${env.BUILD_ENV}_deployed"

If I write it like in the above println, I get

org.jenkinsci.plugins.wo...@336841dd.sandbox_deployed

But I really want this

println "env.sandbox_deployed"

which prints out the correct value of the sandbox_deployed variable. What's the correct syntax?


zil...@gmail.com

unread,
Feb 22, 2021, 10:53:01 PM2/22/21
to Jenkins Users
It's

println "${env."${env.BUILD_ENV}_deployed"}"

Reply all
Reply to author
Forward
0 new messages