Skip to content

Instantly share code, notes, and snippets.

@andrewdmcleod
Created March 9, 2018 12:36
Show Gist options
  • Save andrewdmcleod/133640092f9a0252a69c125e8ae31d06 to your computer and use it in GitHub Desktop.
Save andrewdmcleod/133640092f9a0252a69c125e8ae31d06 to your computer and use it in GitHub Desktop.
pipeline groovy - search and destroy jenkins job
import jenkins.model.*
import hudson.model.*
def jobName = "${JOB_NAME}"
Jenkins.instance.getAllItems(AbstractItem.class).each {
job->
job.builds.each { build->
if (build.getResult().equals(null)) {
buildname = build.toString()
if (buildname.contains(jobName)) {
println("Killing job: " + buildname)
build.doStop();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment