Skip to content

Instantly share code, notes, and snippets.

@gadelkareem
Created July 9, 2020 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gadelkareem/e4e3bff702b655453fa771915c5c4572 to your computer and use it in GitHub Desktop.
Save gadelkareem/e4e3bff702b655453fa771915c5c4572 to your computer and use it in GitHub Desktop.
Kill Jenkins jobs in a folder
import hudson.model.*
import jenkins.model.Jenkins
for (job in Jenkins.instance.items) {
if( job.getFullName().contains('my folder') ){
stopJobs(job)
}
}
def stopJobs(job) {
if (job in com.cloudbees.hudson.plugins.folder.Folder) {
for (child in job.items) {
stopJobs(child)
}
} else if (job in org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) {
for (child in job.items) {
stopJobs(child)
}
} else if (job in org.jenkinsci.plugins.workflow.job.WorkflowJob) {
if (job.isBuilding()) {
for (build in job.builds) {
build.doKill()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment