Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jenkins

People also ask

How can we stop a scheduled job from being executed temporarily in Jenkins?

How can we stop a scheduled job from being executed temporarily? Disable the job from the job details page to temporarily stop all scheduled executions & other factors/events from triggering the job and enable it back to resume the job schedules/triggers.

How can I prevent Jenkins from starting new jobs after a restart?

In order to prevent Jenkins from executing any jobs, you need to put it in "quiet down" mode when it starts up.

How do you temporarily suspend a build during maintenance Jenkins?

Setup a post-initialization script that puts Jenkins into quiet mode right after startup. Show activity on this post. Try using https://wiki.jenkins.io/display/JENKINS/Exclusive+Execution+Plugin. You can keep jenkins in shutdown or Quiet mode for some time till your new instance is ready to function.


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.


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")
                );

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


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.

Once I encounterred a build which could not be stopped by the "Script Console". Finally I solved the problem with these steps:

ssh onto the jenkins server
cd to .jenkins/jobs/<job-name>/builds/
rm -rf <build-number>
restart jenkins