Skip to content

Instantly share code, notes, and snippets.

@stobias123
Last active April 10, 2018 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stobias123/8f9a57337b685c7b57788b6840520fb0 to your computer and use it in GitHub Desktop.
Save stobias123/8f9a57337b685c7b57788b6840520fb0 to your computer and use it in GitHub Desktop.
Jenkins set log rotators
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