Skip to content

Instantly share code, notes, and snippets.

@diogopms
Last active February 16, 2020 14:11
Show Gist options
  • Save diogopms/5d565ac27c4c42c0b7956002b5a66b55 to your computer and use it in GitHub Desktop.
Save diogopms/5d565ac27c4c42c0b7956002b5a66b55 to your computer and use it in GitHub Desktop.
jenkins clear all jobs
import jenkins.model.Jenkins
import hudson.model.Job
Jenkins.instance.allItems(Job).each { job ->
if (job.isBuildable() && job.supportsLogRotator() && job.getProperty(BuildDiscarderProperty) == null) {
def single_job = Jenkins.instance.getItem(job.fullDisplayName)
if(single_job != null) {
single_job.getBuilds().each { it.delete() }
single_job.nextBuildNumber = 1
single_job.save()
println("OK: " + job.fullDisplayName)
}
else {
println("Error: " + job.fullDisplayName)
}
}
}
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment