Accessing Jenkins global property in Extensible Choice using System Groovy Choice Parameter -> Groovy System Script

760 views
Skip to first unread message

zacky azoulay

unread,
Apr 22, 2015, 3:14:54 AM4/22/15
to jenkins...@googlegroups.com
Hi

At this moment I defined a environment variable called TEST1 with the value 'myvalue' under Manage Jenkins -> Configure System -> Global Properties. I have a groovy script when a project is being build containing

def env = System.getenv()
println(env['TEST1'])
println(env['USER'])

i got 

myvalue
lroot

while in the Extensible Choice -> System Groovy Choice Parameter -> Groovy System Script i run the same scripts but i got only lroot

is there a way to get the environment variable in the extensible-choice like jenkins user hudson.model.User.current() or   hudson.model.Hudson.instance.getAuthentication().getName()

thank and regards zacky

Gerd Aschemann

unread,
Oct 11, 2016, 3:12:22 AM10/11/16
to Jenkins Users
We had a similar problem and solved it wrt. https://groups.google.com/forum/#%21topic/jenkinsci-users/KgCGuDmED1Q with the following dynamic parameter script

import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*

nodes = Jenkins.getInstance().getGlobalNodeProperties()
nodes.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)

if ( nodes.size() != 1 ) {
  throw new RuntimeException ("error: unexpected number of environment variable containers: ${nodes.size()}, expected 1!")
}
envVars= nodes.get(0).getEnvVars()
envVars.get("CONFIG_REPO_ADDONS_VERSION")
Reply all
Reply to author
Forward
0 new messages