Delete all offline Jenkins nodes/slaves in Unix/Linux

When you use the slave in Jenkins, there is always a chance that some of the node will no longer exist due to some reason (E.g. network problems; closed port). And if it is a PROD server and it needs to gather projects. For a certain period of time you can gather a large number of disabled cars.

Useful reading:

Installing Jenkins and Jenkins-slave in Unix/Linux

The autobuild Java projects using Jenkins in Unix/Linux

Language setup in Jenkins

Permissions in Jenkins

Monitoring space on server using Jenkins

Setting the theme for Jenkins

Edit/Change password for user Jenkins

Create a Jenkins backup/restore Unix/Linux

The autobuild Java projects using Jenkins in Unix/Linux

I found a few solutions how to do it. Show a visual example of how I managed to kill over 1.5 to zombie nodes.

Jenkins delete all offline nodes

So, one way to delete all offline hosts is to run Groovy script using the Jenkins console. For this, you need Selaginella in Sam Jenkins, then click on “Manage Jenkins” and go to the “script Console”:

In the script, insert:

Closure query = { it.name ==~ /^.*$/ } Closure action = { println('====================') println("Name: ${it.name}") println("LabelString: ${it.labelString}") println("NumExectutors: ${it.numExecutors}") println("RemoteFS: ${it.remoteFS}") println("Mode: ${it.mode}") println("RootPath: ${it.rootPath}") println("Offline: ${it.computer.offline}") if (it.computer.offline) { println("Deleting node: ${it.name}") it.computer.doDoDelete() } } Jenkins.instance.slaves.findAll(query).each(action) return

Click on “RUN” and if a lot of hosts — it takes some time. This example is fully used to PROD the servers the company where I work.

Delete all Jenkins slaves offline

Checked out a different approach of the script to Groovy. A fully working version. To remove a disconnected slave, you need Selaginella in Sam Jenkins, then click on “Manage Jenkins” and go to the “script Console”:

In the script, insert:

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

Click on “RUN” and if a lot of hosts — it takes some time. This example is fully used to PROD the servers the company where I work.

To me these solutions helped and they all work. Thou are more ideas than can be supplemented — will complement the subject.

That’s all, “the Delete all offline Jenkins nodes/slaves in Unix/Linux” is completed.

Source: linux-notes.org

(Visited 8 times, 1 visits today)