Niclas Schumacher
Niclas Schumacher

Reputation: 232

Get Global Variables in jenkins pipeline

I'm creating a jenkins pipeline which is used on different environments / builds. Each Build has different parameters: deploy destination, passwords, usernames etc.

I have some common settings all these builds share, which i have added in the "Jenkins" -> "Configuration" -> "Global properties" as a key value.

Lets say i have added a key value par with : Name : CommonName Value : Money

I now want to be able to, in my pipeline, to access this CommonName variable. I've tried everything.

println "{$params.CommonName}"
println "{$env.CommonName}"
println "{$CommonName}"

Nothing returns me the value from the global configuration.

Not even have a parameter key value on the build to be like: Name : Name Value : ${CommonName}

And then trying to access "${params.Name}", still null in return.

Baseline is, i want to have shared variables across different builds, which i can alter in Jenkins.

Upvotes: 0

Views: 7056

Answers (1)

MaTePe
MaTePe

Reputation: 954

println "${env.CommonName}"
println "${CommonName}"

It should if you move the $-character. I've tried the following and both work:

println GLOBAL_VAR
println env.GLOBAL_VAR

Prints

[Pipeline] echo
global_var_value
[Pipeline] echo
global_var_value

Upvotes: 4

Related Questions