Skip to content

Instantly share code, notes, and snippets.

@tanandy
Created September 27, 2017 07:30
Show Gist options
  • Save tanandy/38696ac65eb61e5670f46528dc482c27 to your computer and use it in GitHub Desktop.
Save tanandy/38696ac65eb61e5670f46528dc482c27 to your computer and use it in GitHub Desktop.
// add-jenkins-param.groovy
// Adds a parameter to all jobs on a Jenkins instance.
// The parameter is then exposed as an environment variable.
import hudson.model.*
key = 'GEM_SOURCE'
value = 'http://rubygems.delivery.puppetlabs.net'
desc = 'The Rubygems Mirror URL'
for(job in Hudson.instance.items) {
println("[ " + job.name + " ] setting " + key + "=" + value)
newParam = new StringParameterDefinition(key, value, desc)
paramDef = job.getProperty(ParametersDefinitionProperty.class)
if (paramDef == null) {
newArrList = new ArrayList<ParameterDefinition>(1)
newArrList.add(newParam)
newParamDef = new ParametersDefinitionProperty(newArrList)
job.addProperty(newParamDef)
}
else {
// Parameters exist! We should check if this one exists already!
found = paramDef.parameterDefinitions.find{ it.name == key }
if (found == null) {
paramDef.parameterDefinitions.add(newParam)
}
}
//job.save()
println()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment