Last active
October 5, 2023 13:26
-
-
Save cvakiitho/2c4e3263be9bb57ab0813b4948da7269 to your computer and use it in GitHub Desktop.
Jenkins script to kill all zombie jobs - jobs with MAX_SURVABILITY -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Resuming build at ... after Jenkins restart