Skip to content

Instantly share code, notes, and snippets.

@marcosborges
Created April 28, 2020 14:53
Show Gist options
  • Save marcosborges/e7e129a4a97e3e299e645312b7ef9262 to your computer and use it in GitHub Desktop.
Save marcosborges/e7e129a4a97e3e299e645312b7ef9262 to your computer and use it in GitHub Desktop.
import jenkins.model.Jenkins
import hudson.model.Job
import jenkins.model.BuildDiscarderProperty
import hudson.tasks.LogRotator
def total = 0
// LogRotator ( daysToKeep, numToKeep, artifactDaysToKeep, artifactNumToKeep)
// daysToKeep: If not -1, history is only kept up to this days.
// numToKeep: If not -1, only this number of build logs are kept.
// artifactDaysToKeep: If not -1 nor null, artifacts are only kept up to this days.
// artifactNumToKeep: If not -1 nor null, only this number of builds have their artifacts kept.
Jenkins.getInstance().getAllItems().each {
if(
it?.getDescriptor().getDisplayName() == "Pipeline" &&
it.isBuildable() &&
it.supportsLogRotator() &&
it.getProperty(BuildDiscarderProperty) == null
) {
println "Configure: ${it.getFullName()}"
it.addProperty(new BuildDiscarderProperty(new LogRotator ( -1, 10, -1, 10)))
total++
}
}
total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment