Skip to content

Instantly share code, notes, and snippets.

@mgasiorowski
Last active April 6, 2017 13:32
Show Gist options
  • Save mgasiorowski/d7e9fcad4339abef1922412dfdc13f0e to your computer and use it in GitHub Desktop.
Save mgasiorowski/d7e9fcad4339abef1922412dfdc13f0e to your computer and use it in GitHub Desktop.
[Jenkins] Find jobs with specific node and change him
import jenkins.model.*
jenkinsInstance = jenkins.model.Jenkins.instance
allItems = jenkinsInstance.getAllItems()
for(int i = 0; i < allItems.size(); i++) {
if(!(allItems[i] instanceof com.cloudbees.hudson.plugins.folder.Folder) && !(allItems[i] instanceof org.jenkinsci.plugins.workflow.job.WorkflowJob) && allItems[i].getAssignedLabelString() =~ "centos"){
allItems[i].setAssignedLabel(jenkins.model.Jenkins.instance.getLabel("centos_7.2"))
println(allItems[i].name + ": " + allItems[i].getAssignedLabel())
}
}
return [:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment