问题描述
在全局属性中的Jenkins配置()中,我定义了一些环境变量。
如何在Groovy Script控制台中访问它们()?
我试着找到合适的解决方案(例如:)
,但似乎它们都不适合我。
我试过例如:
System.getenv(myVar)
和
manager.build.getEnvironment(listener).get('myVar')//没有经理错误
和
import jenkins.model.Jenkins
Jenkins.instance.getProperty('myVar' )//没有方法的签名:hudson.model.Hudson.getProperty()适用于参数类型:(java.lang.String)
和
导入jenkins.model.Jenkins
Jenkins.instance.ParameterValue( DEV_local)
:
def envVars = Jenkins.instance.getGlobalNodeProperties()[0] .getEnvVars()
println envVars ['' myVar']
我参考了下面的链接,介绍如何 set 全局属性编程。
In Jenkins configuration (http://JenkinsURL/configure) within "Global properties" I defined some "Environment variables".
How can I access them in the Groovy Script console (http://JenkinsURL/script)?
I've tried to find appropriate solution (for example the solutions mentioned in: Access to build environment variables from a groovy script in a Jenkins build step (Windows))but it seems that none of them work for me.
I've tried for example:
System.getenv("myVar")
and
manager.build.getEnvironment(listener).get('myVar') //no manager error
and
import jenkins.model.Jenkins
Jenkins.instance.getProperty('myVar') //No signature of method: hudson.model.Hudson.getProperty() is applicable for argument types: (java.lang.String)
and
import jenkins.model.Jenkins
Jenkins.instance.ParameterValue("DEV_local")
You can get global properties like this:
def envVars = Jenkins.instance.getGlobalNodeProperties()[0].getEnvVars()
println envVars['myVar']
I referred to the link below, about how to set global properties programatically.https://groups.google.com/forum/#!topic/jenkinsci-users/KgCGuDmED1Q
这篇关于如何在Jenkins Groovy脚本控制台中获取环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!