Last active
October 9, 2017 14:41
-
-
Save snallami/cc17f1cc5d19d1fdfea8ffbc1d8b9f80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to do the same with org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject?