Skip to content

Instantly share code, notes, and snippets.

@abayer
Created February 9, 2012 19:32
Show Gist options
  • Save abayer/1782288 to your computer and use it in GitHub Desktop.
Save abayer/1782288 to your computer and use it in GitHub Desktop.
import jenkins.model.*
import hudson.util.DescribableList
import hudson.tasks.Builder
import hudson.model.Descriptor
import hudson.tasks.Maven
def newMavenName = "Maven 3.0"
def jobs = Jenkins.instance.items
jobs.each { j ->
if (j instanceof hudson.model.FreeStyleProject || j instanceof hudson.matrix.MatrixProject) {
DescribableList<Builder,Descriptor<Builder>> newBuilders = new DescribableList<Builder,Descriptor<Builder>>(j)
def sawMaven = false
j.builders.each { b ->
if (b instanceof hudson.tasks.Maven) {
if (!b.mavenName.equals(newMavenName)) {
sawMaven = true
println "${j.name} has a build step with old mavenName ${b.mavenName}. Replacing with ${newMavenName}."
Maven newStep = new Maven(b.getTargets(), newMavenName, b.pom, b.@properties, b.jvmOptions, b.usesPrivateRepository())
newBuilders.add(newStep)
} else {
newBuilders.add(b)
}
} else {
newBuilders.add(b)
}
}
if (sawMaven) {
j.builders.replaceBy(newBuilders)
}
}
else if (j instanceof hudson.maven.MavenModuleSet) {
if (!j.mavenName.equals(newMavenName)) {
println "${j.name} is a maven build with old mavenName ${j.mavenName}. Replacing with ${newMavenName}."
j.setMaven(newMavenName)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment