Jenkins administrative groovy scripts 45/30445/1
authorAndrew Grimberg <agrimberg@linuxfoundation.org>
Tue, 1 Dec 2015 17:21:34 +0000 (09:21 -0800)
committerAndrew Grimberg <agrimberg@linuxfoundation.org>
Tue, 1 Dec 2015 17:23:43 +0000 (09:23 -0800)
Make slave cleanup (destruction) groovy scripts accessible to anyone
that has script console access in Jenkins. Mostly this is just me
publishing the scripts so that Thanh has access and Google picks them up
when it indexes our mirror for others that may run into similar problems
that we have when trying to cleanup slaves that are not cleaning up
properly.

Change-Id: I86c5f773879eaff25e4579445ad2b8036bb080f6
Signed-off-by: Andrew Grimberg <agrimberg@linuxfoundation.org>
jenkins-admin/del_computer.groovy [new file with mode: 0644]
jenkins-admin/slay_computer.groovy [new file with mode: 0644]

diff --git a/jenkins-admin/del_computer.groovy b/jenkins-admin/del_computer.groovy
new file mode 100644 (file)
index 0000000..0143887
--- /dev/null
@@ -0,0 +1,39 @@
+/*****************
+* Removes offline slave nodes
+*
+* NOTE: Some slaves can't be removed as the backing instance already is
+* missing but the UI collection didn't get the update. See the
+* slay_computer.groovy for a more drastic destruction
+*
+* NOTE 2: If you have any slaves you want to live through this and you
+* have them currently marked offline you _must_ bring them back online.
+*****************/
+
+import hudson.model.*
+
+def numberOfflineNodes = 0
+def numberNodes = 0
+
+slaveNodes = hudson.model.Hudson.instance
+
+for (slave in slaveNodes.nodes) {
+    def computer = slave.computer
+    numberNodes ++
+    println ""
+    println "Checking computer ${computer.name}:"
+    if (computer.offline) {
+        numberOfflineNodes ++
+        println '\tcomputer.isOffline: ' + slave.getComputer().isOffline()
+        println '\tcomputer.offline: ' + computer.offline
+        println '\tRemoving slave'
+        slaveNodes.removeNode(slave)
+    } else {
+        println '\tcomputer.isOffline: ' + slave.getComputer().isOffline()
+        println '\tcomputer.offline: ' + computer.offline
+    }
+}
+
+println "Number of Offline Nodes: " + numberOfflineNodes
+println "Number of Nodes: " + numberNodes
+
+// vim: sw=4 sts=4 ts=4 et ai :
diff --git a/jenkins-admin/slay_computer.groovy b/jenkins-admin/slay_computer.groovy
new file mode 100644 (file)
index 0000000..97ede6c
--- /dev/null
@@ -0,0 +1,35 @@
+/*****************
+* Completely slays misbehaving slave nodes
+*
+* NOTE: Use del_computer.groovy first! If nodes are still hanging around
+* _then_ consider using this script. This one is mucking around in a
+* location we should not normally be touching, however if a slave
+* refuses to go away (tosses an exception) this _will_ get rid of it.
+*
+* NOTE 2: If you have any slaves you want to live through this and you
+* have them currently marked offline you _must_ bring them back online.
+*****************/
+
+import jenkins.*
+import jenkins.model.*
+import hudson.*
+import hudson.model.*
+
+for (aComputer in Jenkins.instance.computers) {
+    try {
+        println "displayName: " + aComputer.properties.displayName
+        println "offline: " + aComputer.properties.offline
+        println "temporarilyOffline: " + aComputer.properties.temporarilyOffline
+        if (aComputer.properties.offline) {
+            println "Bad node, removing"
+            Jenkins.instance.removeComputer(aComputer)
+        }
+        println ""
+    }
+    catch (NullPointerException nullPointer) {
+        println "NullPointerException caught"
+        println ""
+    }
+}
+
+// vim: sw=4 sts=4 ts=4 et ai :