Created
October 10, 2019 12:22
-
-
Save brandonfl/07ab28a70ff37fb04a8d9d732037abf9 to your computer and use it in GitHub Desktop.
Kill all build and remove queued ones
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 java.util.ArrayList; | |
import hudson.model.*; | |
def q = Jenkins.instance.queue | |
for (queued in Jenkins.instance.queue.items) { | |
q.cancel(queued.task) | |
} | |
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() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment