Created
May 30, 2018 12:06
-
-
Save daxroc/b808629c4ede83aa37b9da8ec57c5d4b to your computer and use it in GitHub Desktop.
Jenkins - Deletes nodes that are idle with matching prefix
This file contains 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 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