Skip to content

Instantly share code, notes, and snippets.

@cvakiitho
Last active October 5, 2023 13:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cvakiitho/2c4e3263be9bb57ab0813b4948da7269 to your computer and use it in GitHub Desktop.
Save cvakiitho/2c4e3263be9bb57ab0813b4948da7269 to your computer and use it in GitHub Desktop.
Jenkins script to kill all zombie jobs - jobs with MAX_SURVABILITY -
def x = 0
for (job in Hudson.instance.getAllItems(org.jenkinsci.plugins.workflow.job.WorkflowJob)) {
try{
def isZombie = job.getLastBuild().dump()==~ /.*state=null.*/
def isRunning = job.getLastBuild().completed
if(!isRunning && isZombie ){
x = x +1
println "Candidate for Zombie: ${job}"
job.getLastBuild().doKill()
}
}catch(e){
}
}
println "Number of zombies: ${x}"
//another option
runningBuilds = Jenkins.instance.getView('All').getBuilds().findAll() { it.getResult().equals(null) }
runningBuilds.each { branch->branch.doKill() }
@cvakiitho
Copy link
Author

Resuming build at ... after Jenkins restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment