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

When using the Jenkins Docker Plugin, it is possible due to an error that the flocks cannot be started. I did not pay attention, and at the moment I have thousands of autonomous nodes that have not been started.

BOTTOM LINE - is there a way to batch delete slaves in Jenkin, clear all offline nodes, or even delete all nodes? Restarting the Jenkins server did not help, and I could not find a way in the Jenkins API.

Understand any idea before I start writing a selenium script or something ...

Thank you very much!

+6
source share
3 answers

There is a script with a section marked for deleting nodes.

It runs in the Jenkins script console

for (aSlave in hudson.model.Hudson.instance.slaves) { println('===================='); println('Name: ' + aSlave.name); println('getLabelString: ' + aSlave.getLabelString()); println('getNumExectutors: ' + aSlave.getNumExecutors()); println('getRemoteFS: ' + aSlave.getRemoteFS()); println('getMode: ' + aSlave.getMode()); println('getRootPath: ' + aSlave.getRootPath()); println('getDescriptor: ' + aSlave.getDescriptor()); println('getComputer: ' + aSlave.getComputer()); println('\tcomputer.isAcceptingTasks: ' + aSlave.getComputer().isAcceptingTasks()); println('\tcomputer.isLaunchSupported: ' + aSlave.getComputer().isLaunchSupported()); println('\tcomputer.getConnectTime: ' + aSlave.getComputer().getConnectTime()); println('\tcomputer.getDemandStartMilliseconds: ' + aSlave.getComputer().getDemandStartMilliseconds()); println('\tcomputer.isOffline: ' + aSlave.getComputer().isOffline()); println('\tcomputer.countBusy: ' + aSlave.getComputer().countBusy()); //if (aSlave.name == 'NAME OF NODE TO DELETE') { // println('Shutting down node!!!!'); // aSlave.getComputer().setTemporarilyOffline(true,null); // aSlave.getComputer().doDoDelete(); //} println('\tcomputer.getLog: ' + aSlave.getComputer().getLog()); println('\tcomputer.getBuilds: ' + aSlave.getComputer().getBuilds()); } 
+11
source

This is Copy>Paste>Run version of KeepCalmAndCarryOn answer. Go to Jenkins Management> Script Console> copy and 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

+1
source

Thanks for the great answer.

Another way to do this is to manually edit the $ {JENKINS_HOME} /config.xml file manually (and, for example, find / replace by regular expression).

0
source

Source: https://habr.com/ru/post/970419/


All Articles