With the new multibranch PR jobs we’ve noticed that some jobs for closed PRs were kept although we are very strict with cleaning up after the jobs (a legacy of an unwieldy and bloated repo).
The multibranch scan log claimed that jobs were still running and therefore the PR jobs could not be deleted. This was indeed the case. Although no process was running and Jenkins had been restarted a couple of times, there was seemingly no way of getting rid of these zombies.
Open the script console (from the ‘Manage Jenkins’ page) and type
Jenkins.instance.getItemByFullName("JobName").getBuildByNumber(JobNumber) .finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build"));
replacing JobName with the name of your job and JobNumber with the number of the build job you want to terminate.
And that is how you kill the Jenkins zombies.
I’ve obviously googled that…