forked from dennyzhang/cheatsheet-jenkins-groovy-A4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-dead-executors.groovy
executable file
·34 lines (33 loc) · 1.11 KB
/
find-dead-executors.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!groovy
//-------------------------------------------------------------------
// @copyright 2018 DennyZhang.com
// Licensed under MIT
// https://www.dennyzhang.com/wp-content/mit_license.txt
//
// File: find-dead-executors.groovy
// Author : Denny <https://www.dennyzhang.com/contact>
// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4
// --
// Created : <2018-04-20>
// Updated: Time-stamp: <2019-05-01 14:09:37>
//-------------------------------------------------------------------
// https://gist.github.com/malonem/5045386
// get handle to build output
def config = new HashMap()
def bindings = getBinding()
config.putAll(bindings.getVariables())
def out = config['out']
for (aSlave in hudson.model.Hudson.instance.slaves) {
// check if executor is dead
execList = aSlave.getComputer().getExecutors()
for( exec in execList ) {
if (exec.getCauseOfDeath()) {
println("\tSlave ${aSlave.name} has a dead executor.")
println("Error:")
exec.getCauseOfDeath().printStackTrace(out)
println('\n')
println("\tRemoving Dead Executor.")
exec.doYank()
}
}
}