Variable indirection in a pipeline?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Variable indirection in a pipeline?

zil...@gmail.com

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.workflow.cps.EnvActionImpl@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?


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/85f59145-f7c3-4eb9-9b23-09684bcec783n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Variable indirection in a pipeline?

zil...@gmail.com
It's

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

On Monday, February 22, 2021 at 9:25:50 PM UTC-5 [hidden email] wrote:

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?


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/d4057381-3305-49c3-b198-521073ba3c50n%40googlegroups.com.