Skip to content

Instantly share code, notes, and snippets.

@abihf
Created March 20, 2020 18:33
Show Gist options
  • Save abihf/92e9fe6d66fe360c6d0d1671fa477997 to your computer and use it in GitHub Desktop.
Save abihf/92e9fe6d66fe360c6d0d1671fa477997 to your computer and use it in GitHub Desktop.
import jenkins.model.Jenkins
Jenkins.instanceOrNull.allItems(hudson.model.Job).each { job ->
if (job.isBuildable() && job.supportsLogRotator() && job.getProperty(jenkins.model.BuildDiscarderProperty) == null) {
println "Processing \"${job.fullDisplayName}\""
try {
job.setBuildDiscarder(new hudson.tasks.LogRotator ( 14, -1, 14, -1))
println "${job.fullName} is updated"
} catch (Exception e) {
// Some implementation like for example the hudson.matrix.MatrixConfiguration supports a LogRotator but not setting it
println "[WARNING] Failed to update ${job.fullName} of type ${job.class} : ${e}"
}
}
}
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment