Created
October 27, 2017 07:56
-
-
Save halfb00t/abe67e9cc8377aeb34a4b24e863adffa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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