Skip to content

Instantly share code, notes, and snippets.

@snallami
Last active October 9, 2017 14:41
Show Gist options
  • Save snallami/cc17f1cc5d19d1fdfea8ffbc1d8b9f80 to your computer and use it in GitHub Desktop.
Save snallami/cc17f1cc5d19d1fdfea8ffbc1d8b9f80 to your computer and use it in GitHub Desktop.
import hudson.model.*
disableChildren(Hudson.instance.items)
def disableChildren(items) {
def daysToKeep = 14
def numToKeep = 10
def artifactDaysToKeep = -1
def artifactNumToKeep = -1
for (item in items) {
if (item.class.canonicalName != 'com.cloudbees.hudson.plugins.folder.Folder') {
if(item instanceof FreeStyleProject || item instanceof hudson.maven.MavenModuleSet) {
println("=====================")
println("JOB: " + item.name)
println("Job type: " + item.getClass())
if(item.buildDiscarder == null) {
println("No BuildDiscarder")
println("Set BuildDiscarder to LogRotator")
} else {
println("BuildDiscarder: " + item.buildDiscarder.getClass())
println("Found setting: " + "days to keep=" + item.buildDiscarder.daysToKeepStr + "; num to keep=" + item.buildDiscarder.numToKeepStr + "; artifact day to keep=" + item.buildDiscarder.artifactDaysToKeepStr + "; artifact num to keep=" + item.buildDiscarder.artifactNumToKeepStr)
println("Already exists - no changes required, just return back")
continue
}
item.buildDiscarder = new hudson.tasks.LogRotator(daysToKeep,numToKeep, artifactDaysToKeep, artifactNumToKeep)
item.save()
println("")
}
} else {
disableChildren(((com.cloudbees.hudson.plugins.folder.Folder) item).getItems())
}
}
}
@makarovandr
Copy link

How to do the same with org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment