Created
June 3, 2016 20:35
-
-
Save snallami/dce71a66af5db39607eae7f8a69c2c91 to your computer and use it in GitHub Desktop.
Groovy script to update jenkins label
This file contains 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
import hudson.model.* | |
import hudson.model.labels.LabelAtom | |
updateJenkinsLabel(Hudson.instance.items,"<Replace With Old Label>", "<Replace With new Label") | |
def updateJenkinsLabel(items, oldLabel, newLabel) { | |
for (item in items) { | |
// Find out if it is a folder | |
if (item.class.canonicalName != 'com.cloudbees.hudson.plugins.folder.Folder') { | |
if(item instanceof FreeStyleProject || item instanceof hudson.maven.MavenModuleSet) { | |
if(item.assignedLabel != null && item.assignedLabel.name.equals(oldLabel) ) { | |
item.assignedLabel = new LabelAtom(newLabel) | |
item.save() | |
println("JOB: " + item.name + " has label "+oldLabel + " updated with "+newLabel) | |
} | |
} | |
} else { | |
updateJenkinsLabel(((com.cloudbees.hudson.plugins.folder.Folder) item).getItems(), oldLabel, newLabel) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment