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

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 doesn't show anything either. I've checked on our build servers and the job doesn't actually seem to be running at all.

Is there a way to tell jenkins that the job is "done", by editing some file or lock or something? Since we have a lot of jobs we don't really want to restart the server.


Solution 1:

I had also the same problem and fix it via Jenkins Console.

Go to "Manage Jenkins" > "Script Console" and run a script:

 Jenkins .instance.getItemByFullName("JobName")
        .getBuildByNumber(JobNumber)
        .finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build")); 

You'll have just specify your JobName and JobNumber.

Solution 2:

Go to "Manage Jenkins" > "Script Console" to run a script on your server to interrupt the hanging thread.

You can get all the live threads with Thread.getAllStackTraces() and interrupt the one that's hanging.

Thread.getAllStackTraces().keySet().each() {
  t -> if (t.getName()=="YOUR THREAD NAME" ) {   t.interrupt();  }
}

UPDATE:

The above solution using threads may not work on more recent Jenkins versions. To interrupt frozen pipelines refer to this solution (by alexandru-bantiuc) instead and run:

Jenkins.instance.getItemByFullName("JobName")
                .getBuildByNumber(JobNumber)
                .finish(
                        hudson.model.Result.ABORTED,
                        new java.io.IOException("Aborting build")
                );

Solution 3:

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

Solution 4:

Without having to use the script console or additional plugins, you can simply abort a build by entering /stop, /term, or /kill after the build URL in your browser.

Quoting verbatim from the above link:

Pipeline jobs can by stopped by sending an HTTP POST request to URL endpoints of a build.

  • <BUILD ID URL>/stop - aborts a Pipeline.
  • <BUILD ID URL>/term - forcibly terminates a build (should only be used if stop does not work.
  • <BUILD ID URL>/kill - hard kill a pipeline. This is the most destructive way to stop a pipeline and should only be used as a last resort.