Skip to content

Instantly share code, notes, and snippets.

@daxroc
Last active May 30, 2018 12:13
Show Gist options
  • Save daxroc/c8676dfdc9df01e5e615b1e8a452d71f to your computer and use it in GitHub Desktop.
Save daxroc/c8676dfdc9df01e5e615b1e8a452d71f to your computer and use it in GitHub Desktop.
Delete jenkins agent node/computers that have retried 5 times
String agentList = ""
String agentPrefix = "example"
Integer agentTotal = 0
Integer ofType = 0
Integer ofDeleted = 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)){
//println it.computer.offlineCause.toString()
if (it.computer.offlineCause.toString().contains('Time out for last 5 try')) {
agentList += it.nodeName + "\n"
it.computer.doDoDelete()
ofDeleted +=1
}
ofType +=1
}
agentTotal +=1
}
println "Deleted Agent list: \n" + agentList
println "Total: ${agentTotal} Total type: ${ofType} Deleted: ${ofDeleted}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment