在詹金斯管道中获取全局变量 [英] Get Global Variables in jenkins pipeline
问题描述
我正在创建一个jenkins管道,该管道可用于不同的环境/构建.每个内部版本都有不同的参数:部署目标,密码,用户名等.
I'm creating a jenkins pipeline which is used on different environments / builds. Each Build has different parameters: deploy destination, passwords, usernames etc.
我具有所有这些构建共享的一些通用设置,这些设置已添加到"Jenkins"->配置"->全局属性"中作为键值.
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
我现在希望能够在我的管道中访问此CommonName变量. 我已经尝试了一切.
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.
构建中甚至没有参数键值,例如: 姓名:姓名 值:$ {CommonName}
Not even have a parameter key value on the build to be like: Name : Name Value : ${CommonName}
然后尝试访问"$ {params.Name}",但仍然返回null.
And then trying to access "${params.Name}", still null in return.
基准是,我想在不同版本之间共享变量,我可以在Jenkins中进行更改.
Baseline is, i want to have shared variables across different builds, which i can alter in Jenkins.
推荐答案
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
打印
[Pipeline] echo
global_var_value
[Pipeline] echo
global_var_value
这篇关于在詹金斯管道中获取全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!