How to stop an unstoppable zombie job on Jenkins without restarting the server?

前端 未结 27 1516
南旧
南旧 2020-11-27 09:18

Our Jenkins server has a job that has been running for three days, but is not doing anything. Clicking the little X in the corner does nothing, and the console output log do

相关标签:
27条回答
  • 2020-11-27 09:26

    In case you got a Multibranch Pipeline-job (and you are a Jenkins-admin), use in the Jenkins Script Console this script:

    Jenkins.instance
    .getItemByFullName("<JOB NAME>")
    .getBranch("<BRANCH NAME>")
    .getBuildByNumber(<BUILD NUMBER>)
    .finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build"));
    

    From https://issues.jenkins-ci.org/browse/JENKINS-43020

    If you aren't sure what the full name (path) of the job is, you may use the following snippet to list the full name of all items:

      Jenkins.instance.getAllItems(AbstractItem.class).each {
        println(it.fullName)
      };
    

    From https://support.cloudbees.com/hc/en-us/articles/226941767-Groovy-to-list-all-jobs

    0 讨论(0)
  • 2020-11-27 09:26

    Alexandru Bantiuc's answer worked well for me to stop the build, but my executors were still showing up as busy. I was able clear the busy executor status using the following

    server_name_pattern = /your-servers-[1-5]/
    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.interrupt()
          }
        }
      }
    }
    
    0 讨论(0)
  • 2020-11-27 09:27

    The first proposed solution is pretty close. If you use stop() instead of interrupt() it even kills runaway threads, that run endlessly in a groovy system script. This will kill any build, that runs for a job. Here is the code:

    Thread.getAllStackTraces().keySet().each() {
        if (it.name.contains('YOUR JOBNAME')) {  
          println "Stopping $it.name"
          it.stop()
        }
    }
    
    0 讨论(0)
  • 2020-11-27 09:27

    This works for me everytime:

    Thread.getAllStackTraces().keySet().each() {
    if (it.name.contains('YOUR JOBNAME')) {  
      println "Stopping $it.name"
      it.stop()
    }
    

    Thanks to funql.org

    0 讨论(0)
  • 2020-11-27 09:31

    Build-timeout Plugin can come handy for such cases. It will kill the job automatically if it takes too long.

    0 讨论(0)
  • 2020-11-27 09:31

    A utility I wrote called jkillthread can be used to stop any thread in any Java process, so long as you can log in to the machine running the service under the same account.

    0 讨论(0)
提交回复
热议问题