Last active
April 10, 2018 18:56
-
-
Save stobias123/8f9a57337b685c7b57788b6840520fb0 to your computer and use it in GitHub Desktop.
Jenkins set log rotators
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
jenkins.model.Jenkins.instance.getAllItems().each { | |
if ( it.getClass() != com.cloudbees.hudson.plugins.folder.Folder && it.getClass() != org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject ){ | |
try { | |
if (it.getLastBuild().number != null && it.getLastBuild().number > 10 ){ | |
if(it.getLogRotator() == null){ | |
println it.getFullName() + " Build number " + it.getLastBuild().number; | |
if(it.getClass() != org.jenkinsci.plugins.workflow.job.WorkflowJob){ | |
println ' ---> Setting a log rotator that will delete any artifacts/builds older than number 200' | |
//job.logRotator = new hudson.tasks.LogRotator ( null, 200, 00, 200) | |
} | |
if(it.getClass() == org.jenkinsci.plugins.workflow.job.WorkflowJob){ | |
println ' ---> Workflow job. Setting a log rotator that will keep all artifacts to day/number 99999' | |
//job.logRotator = new hudson.tasks.LogRotator ( null, 200, 99999, 999999) | |
} | |
} | |
} | |
}catch(java.lang.NullPointerException ex){ | |
} | |
} | |
} | |
return null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment