Skip to content

Instantly share code, notes, and snippets.

@devromans
Created October 11, 2022 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devromans/77eb763b44de1675778178f7d0cc9a18 to your computer and use it in GitHub Desktop.
Save devromans/77eb763b44de1675778178f7d0cc9a18 to your computer and use it in GitHub Desktop.
Jenkins Groovy snippets
for(job in jenkins.model.Jenkins.theInstance.getAllItems()) {
println "\nJob: $job.name"
job.delete()
}
jenkins.model.Jenkins.theInstance.getView("WORKERS").items.each { job ->
println "\nJob: $job.name"
job.disabled = true
}
MAX_BUILDS = 1
for (job in Jenkins.instance.items) {
def recent = job.builds.limit(MAX_BUILDS)
for (build in job.builds) {
if (!recent.contains(build)) {
build.delete()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment