Skip to content

Instantly share code, notes, and snippets.

@gwsu2008
Created May 21, 2020 23:21
Show Gist options
  • Save gwsu2008/0555ab4efbdecb654dddc6697daaadd6 to your computer and use it in GitHub Desktop.
Save gwsu2008/0555ab4efbdecb654dddc6697daaadd6 to your computer and use it in GitHub Desktop.
jenkins-groovy-get-nodes.groovy
import hudson.FilePath
import hudson.model.Node
import hudson.model.Slave
import jenkins.model.Jenkins
Jenkins jenkins = Jenkins.instance
for (Node node in jenkins.nodes) {
// Make sure slave is online
if (!node.toComputer().online) {
println "Node '$node.nodeName' is currently offline - skipping workspace cleanup"
continue
}
println "Node '$node.nodeName' is online - performing cleanup:"
// Do some cleanup
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment