Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - Is there a way to remove all offline nodes (slaves) / batch remove nodes / delete all nodes?

Tags:

While using the Jenkins Docker Plugin, probably because of an error, swarms cannot be launched. I didn't pay attention and at the moment I have thousands of offline nodes, that were failed to launch.

BOTTOM LINE - Is there a way to batch remove nodes (slaves) in Jenkin, clean all offline nodes or even delete all nodes? Restating the Jenkins server didn't help, and I couldn't find a way in the Jenkins API.

Will appreciate any idea, before I'm starting to write a Selenium script or something...

Many thanks!

like image 501
AlonL Avatar asked Jun 06 '14 00:06

AlonL


People also ask

How do you restrict Jenkins job to execute on a particular node?

Use Authorize Project plugin to assign authentication to your builds. Then Just set Computer/Build permissions for you nodes (Can be done in Role Strategy plugin for example) Use Job Restrictions Plugin to restrict access to node via Node properties.

How do I delete an agent in Jenkins?

Deleting a single agentOn the Agents page, click the Delete Agent link in the Action column for the agent you want to delete. This action removes the agent from the database. On the Agent Details page, click Delete Agent to delete that displayed agent.

How do Jenkins nodes work?

The Jenkins master acts to schedule the jobs, assign slaves, and send builds to slaves to execute the jobs. It will also monitor the slave state (offline or online) and get back the build result responses from slaves and the display build results on the console output.


1 Answers

This is the Copy>Paste>Run version of KeepCalmAndCarryOn answer. Go to manage Jenkins > Script Console > copy & paste this code > Run

for (aSlave in hudson.model.Hudson.instance.slaves) {
    if (aSlave.getComputer().isOffline()) {
        aSlave.getComputer().setTemporarilyOffline(true,null);
        aSlave.getComputer().doDoDelete();
    }
}

enter image description here

like image 140
Nayana Adassuriya Avatar answered Sep 19 '22 18:09

Nayana Adassuriya