Get Global Variables in jenkins pipeline

删除回忆录丶 提交于 2019-12-25 02:22:30

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/46585958/get-global-variables-in-jenkins-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!