Created
July 9, 2020 14:05
-
-
Save gadelkareem/e4e3bff702b655453fa771915c5c4572 to your computer and use it in GitHub Desktop.
Kill Jenkins jobs in a folder
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 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