Skip to content

Instantly share code, notes, and snippets.

@johnyzed
Created June 9, 2015 05:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnyzed/2af71090419af2b20c5a to your computer and use it in GitHub Desktop.
Save johnyzed/2af71090419af2b20c5a to your computer and use it in GitHub Desktop.
alter jenkins global parameter
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
nodes = Jenkins.getInstance().getGlobalNodeProperties()
nodes.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
if ( nodes.size() != 1 ) {
println("error: unexpected number of environment variable containers: "
+ nodes.size()
+ " expected: 1")
} else {
envVars= nodes.get(0).getEnvVars()
envVars.put(args[0],args[1])
Jenkins.getInstance().save()
println("okay")
}
@dserodio
Copy link

dserodio commented Sep 9, 2015

This script can be made a lot groovier :)

nodes = Jenkins.instance.globalNodeProperties

nodes.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)

if ( nodes.size() != 1 ) {
  println("error: unexpected number of environment variable containers: ${nodes.size()}, expected: 1")
} else {
  envVars = nodes[0].envVars
  envVars[args[0]] = args[1]
  Jenkins.instance.save()
  println("okay")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment