Last active
April 12, 2022 06:00
-
-
Save dee-kryvenko/51fdafaeff886e9dac5386bff555246c to your computer and use it in GitHub Desktop.
Jenkins find and abort builds stuck without executor
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
import com.cloudbees.hudson.plugins.folder.AbstractFolder | |
import org.jenkinsci.plugins.workflow.job.WorkflowJob | |
import hudson.model.FreeStyleProject | |
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException | |
import hudson.model.Result | |
projects = [] | |
def getProjects(def items) { | |
items.each { | |
if (it instanceof AbstractFolder) { | |
getProjects(it.getItems()) | |
} else if (it instanceof WorkflowJob || it instanceof FreeStyleProject) { | |
projects << it | |
} else { | |
throw new RuntimeException("Unrecognized job type: ${it.class}") | |
} | |
} | |
} | |
getProjects(Jenkins.instance.getAllItems()) | |
projects.each { | |
it.getBuilds().each { | |
if (it.isBuilding() && (it.parent.isDisabled() || it.getExecutor() == null)) { | |
println it.getFullDisplayName() + " : " + it.class | |
it.doTerm() | |
it.doStop() | |
it.doKill() | |
FlowInterruptedException suddenDeath = new FlowInterruptedException(Result.ABORTED) | |
it.finish(Result.ABORTED, suddenDeath) | |
it.getSettableExecutionPromise().setException(suddenDeath) | |
} | |
} | |
} | |
println projects.size() | |
return "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment