Last active
August 29, 2015 14:00
-
-
Save colinPL/11159398 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 to the job's environment as `$PARAM_KEY`. | |
| import hudson.model.* | |
| key = 'GEM_SOURCE' | |
| value = 'http://rubygems.delivery.puppetlabs.net:5000' | |
| desc = 'The rubygems URL' | |
| for(job in Hudson.instance.items) { | |
| // TODO: this doesn't work. Don't use it! | |
| 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