How to get environment variable in Jenkins Groovy script console?

In the Jenkins configuration ( http: // JenkinsURL / configure ) in the Global Properties section, I defined some "environment variables".

How can I access them in the Groovy Script console ( http: // JenkinsURL / script )?

I tried to find a suitable solution (for example, the solutions mentioned in: Access to building environment variables from Groovy Script at the Jenkins build phase (Windows) ) but it seems that none of them work for me.

I 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") 
+5
source share
1 answer

You can get global properties as follows:

 def envVars = Jenkins.instance.getGlobalNodeProperties()[0].getEnvVars() println envVars['myVar'] 

I referenced the link below on how to programmatically set global properties. https://groups.google.com/forum/#!topic/jenkinsci-users/KgCGuDmED1Q

+7
source

Source: https://habr.com/ru/post/1258707/


All Articles