Created
May 27, 2021 17:25
-
-
Save scrain/745a68e8115af2f8a766a4fbe6903b89 to your computer and use it in GitHub Desktop.
Jenkins script to replace all job labels from one value to another
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
String oldLabel = 'foo' | |
String newLabel = 'bar' | |
boolean dryRun = true | |
for (item in Jenkins.instance.getAllItems(Job.class).findAll{it.hasProperty('assignedLabel')}) { | |
if (oldLabel == item.assignedLabel.toString()) { | |
println "${item.name}: label being updated from '${oldLabel}' to '${newLabel}'" | |
if (!dryRun) { | |
item.setAssignedLabel(new hudson.model.labels.LabelAtom(newLabel)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment