Skip to content

Instantly share code, notes, and snippets.

@scrain
Created May 27, 2021 17:25
Show Gist options
  • Save scrain/745a68e8115af2f8a766a4fbe6903b89 to your computer and use it in GitHub Desktop.
Save scrain/745a68e8115af2f8a766a4fbe6903b89 to your computer and use it in GitHub Desktop.
Jenkins script to replace all job labels from one value to another
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