Skip to content

Instantly share code, notes, and snippets.

@cvakiitho
Last active October 5, 2023 13:26
Show Gist options
  • Select an option

  • Save cvakiitho/2c4e3263be9bb57ab0813b4948da7269 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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