Skip to content

Instantly share code, notes, and snippets.

@akostadinov
Created December 22, 2020 19:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akostadinov/2380acfc5df3518ab5b99625734c52da to your computer and use it in GitHub Desktop.
Save akostadinov/2380acfc5df3518ab5b99625734c52da to your computer and use it in GitHub Desktop.
Cancel all running Jenkins builds with system groovy script
import jenkins.model.Jenkins
def numCancels = 0;
Jenkins.instance.getAllItems(Job.class).each{
def job = it
for (build in job.builds) {
if (build.isBuilding()) { build.doStop(); numCancels++; }
}
}
println("${numCancels}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment