epcim of DevOps
8/17/2017 - 4:01 PM

Stop all jenkins executors

Stop all jenkins executors

server_name_pattern = /jsl0[1-9]/
jenkins.model.Jenkins.instance.getComputers().each { computer ->
  if (computer.getName().find(server_name_pattern)) {
    println computer.getName()
    execList = computer.getExecutors()      
    for( exec in execList ) {
      busyState = exec.isBusy() ? ' busy' : ' idle'
      println '--' + exec.getDisplayName() + busyState
      if (exec.isBusy()) {
        exec.stop()
        exec.interrupt()
      }
    }
  }
}