Jenkins : diskspace requirement tips

Jenkins is great tool but I already wrote the default value don’t help to keep it running for a long time without terrabytes of disks. So let’s manage our diskspace requirement for maven builds using the various option of jenkins and the system groovy scripts.

Disable maven artefact archiving

This option will tell jenkins to collect pom,jars,wars,ears as they are produced by maven. This is rarely usefull when you use an enterprise repository. This option is enabled by default… so if you aren’t using it… disable it !

to do so you need to go in each job definition and check :

Build > Advanced > Disable automatic artifact archiving

As lazy programmer, you may be know that jenkins offer a jenkins script console.
So you can fix artefact archiving in a single batch with the following script :

String format ='%-45s | %-20s | %-10s | %-10s | %-30s'
def readonly = false
activeJobs = hudson.model.Hudson.instance.items.findAll
    {job -> job.isBuildable() && job instanceof hudson.maven.MavenModuleSet}
def oneline= { str ->   if (str==null)     return "";  str.replaceAll("[\n\r]", " - ")}
println String.format(format , "job", "scm trigger","last status"," logrot","archiving")
println "-------------------------------------------------------------------------------------------------------------------------------"
activeJobs.each{run ->
    println String.format(format ,,oneline(run.getTrigger(hudson.triggers.Trigger.class)?.spec), run?.lastBuild?.result, run.logRotator.getDaysToKeep()+" "+run.logRotator.getNumToKeepStr(), ""+run.isArchivingDisabled()) ; 
    if (!run.isArchivingDisabled() && !readonly ) {        

adjust the readonly variable to true to fix them automatically 😉

job                  | scm trigger          | last status |  logrot  | archiving                    
myproject_ci         | 24 * * * *           | SUCCESS    | -1 10     | true

Discard Old Build

you can easily locate the jobs leaking logs

noLogRotation = hudson.model.Hudson.instance.items.findAll
                   {job -> job.isBuildable() && job.logRotator==null}
noLogRotation.each() {println}

and fix them also by providing a logRotator

def jobs = hudson.model.Hudson.instance.items.findAll
                                         { !it.logRotator && !it.disabled }
jobs.each { job ->
   // days to keep, num to keep, artifact days to keep, num to keep 
   job.logRotator = new hudson.tasks.LogRotator ( 30, 40, 1, 1) 
   println "$ fixed " 
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: