Created
September 10, 2019 17:48
-
-
Save steven-terrana/a0d3b7b3a081f86524ff9ff21b2cec9c to your computer and use it in GitHub Desktop.
Revisions
-
steven-terrana created this gist
Sep 10, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import java.util.ArrayList import hudson.model.*; // Remove everything which is currently queued def q = Jenkins.instance.queue for (queued in Jenkins.instance.queue.items) { q.cancel(queued.task) } // stop all the currently running jobs for (job in Jenkins.instance.items) { 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() } } } }