Skip to content

Instantly share code, notes, and snippets.

@kumbasar
Created August 2, 2022 04:58
Show Gist options
  • Save kumbasar/a3e255b6038c2fda2a3f7aebe6727fbd to your computer and use it in GitHub Desktop.
Save kumbasar/a3e255b6038c2fda2a3f7aebe6727fbd to your computer and use it in GitHub Desktop.
Cancel Jenkins Queues and delete offline nodes
import hudson.model.*
import jenkins.model.Jenkins
def q = Jenkins.instance.queue
q.items.findAll { it.task.name }.each { q.cancel(it.task) }
for (aSlave in hudson.model.Hudson.instance.slaves) {
if (aSlave.getComputer().isOffline() /* || aSlave.getComputer().isOnline() */) {
aSlave.getComputer().setTemporarilyOffline(true,null);
aSlave.getComputer().doDoDelete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment