如何在Jenkins Groovy脚本控制台中获取环境变量? [英] How to get environment variable in Jenkins Groovy script console?

查看:215
本文介绍了如何在Jenkins Groovy脚本控制台中获取环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在全局属性中的Jenkins配置( http:// JenkinsURL / configure )中,我定义了一些环境变量。



如何在Groovy Script控制台中访问它们( http: // JenkinsURL / script )?



我试着找到合适的解决方案(例如:访问从詹金斯的groovy脚本构建环境变量构建步骤(Windows)
,但似乎它们都不适合我。



我试过例如:

  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 全局属性编程。
https://groups.google.com/forum/# !topic / jenkinsci-users / KgCGuDmED1Q

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脚本控制台中获取环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆