Skip to content

Instantly share code, notes, and snippets.

@daxroc
Created May 30, 2018 12:06
Show Gist options
  • Save daxroc/b808629c4ede83aa37b9da8ec57c5d4b to your computer and use it in GitHub Desktop.
Save daxroc/b808629c4ede83aa37b9da8ec57c5d4b to your computer and use it in GitHub Desktop.
Jenkins - Deletes nodes that are idle with matching prefix
String agentList = ""
String agentPrefix = "Ubuntu"
Integer total = 0
Integer oftype = 0
Integer deleted = 0
// Go through nodes and build a list of agents matching the supplied online/offline booleans
Jenkins.instance.nodes.each {
//println "Checking agent: $it.nodeName"
if (it.nodeName.contains(agentPrefix)){
if (it.computer.isIdle()) {
agentList += it.nodeName + "\n"
it.computer.doDoDelete()
deleted += 1
}
oftype += 1
}
total += 1
}
println "Deleted Agent list: \n" + agentList
println "Total: ${total} Type Total: ${oftype} Deleted: ${deleted}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment