Skip to content

Instantly share code, notes, and snippets.

@malonem
Created February 27, 2013 05:30
Show Gist options
  • Save malonem/5045386 to your computer and use it in GitHub Desktop.
Save malonem/5045386 to your computer and use it in GitHub Desktop.
Jenkins script to find dead executors and remove them.
// 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()
}
}
}
Copy link

ghost commented Oct 6, 2015

I have single executor on master. So tried instance.master but got exception and I want to start that dead executor. Tried to search method for starting executor but no success.

@malonem
Copy link
Author

malonem commented Oct 7, 2015

Looks like this was using some old APIs, try it this way ...

// get handle to build output
def config = new HashMap()
def bindings = getBinding()
config.putAll(bindings.getVariables())
def out = config['out']


  jenkins.model.Jenkins.instance.getComputers().each { computer ->
  // check if executor is dead
  execList = computer.getExecutors()      
  for( exec in execList ) {
    if (exec.getCauseOfDeath()) {
      println("\tNode: ${computer.getDisplayName()}, executer ${exec.getDisplayName()} is dead.")
      println("Error:")
      exec.getCauseOfDeath().printStackTrace(out) 
      println('\n')
      println("\tRemoving Dead Executor.")
      exec.doYank()
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment