45

I'm using Jenkins to execute daily tasks with my projects, but every execution, Jenkins stores a 20MB dir in PROJECT_HOME/builds, so after a lot of executions, the space in the disk of every project is huge (10GB for some Jenkins tasks).

It isn't very important for me to store the result of the previous executions, so what I want to know is that if exists a way to say Jenkins no to store that information.

Does anybody know how to avoid Jenkins to store result of old executions?

1

6 Answers 6

56

If you go into the project's configuration page, you will find a checkbox labeled "Discard Old Builds". Enabling this allows you to specify both the number of days to retain builds for and the maximum number of builds to keep.

6
  • In my case, I couldn't actually change the configuration because of lack of free space, so I had to get on the system and manually delete the old builds.
    – ThomasW
    Mar 18, 2014 at 5:40
  • BTW, I haven't used this yet, but I just found the Configuration Slicing Plugin that lets you specify the # of builds to keep (etc) across all builds on the Jenkins machine, from one location wiki.jenkins-ci.org/display/JENKINS/…
    – Allen Rice
    Feb 11, 2016 at 18:48
  • 1
    @jwernerny Once you've ticked that, how do you force it to do the discard operation?
    – Carlos
    Oct 27, 2017 at 12:07
  • 1
    @Carlos It's been a while (6 years?), but as I remember, cleaning up of old builds happens when the build is run. (In other words, try building the job.)
    – jwernerny
    Oct 27, 2017 at 17:26
  • The jenkins UI no longer lists this option. Please update your answer. Apr 10, 2018 at 21:43
24

If you want to make Jenkins discard all old builds without having to re-run all builds then you can run this bit of script taken from http://scriptlerweb.appspot.com/script/show/85001:

def jobs = Hudson.instance.items 

jobs.findAll{it.logRotator}.each {
  println("JOB : "+ it.name)
  try {
    println(it.logRotator.perform(it))
  } catch (Exception e) {
    println("It didn't work: "+ e)
  }
}

Note: to run the script on Jenkins you can go to the script console http://<server>/jenkins/script. More info on the console here: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console

0
6

If like me, you only noticed you had run out of space when you got a build failure then you will want to clear up some of the older builds to free up some space. First change the configuration to discard old builds as jwernerny mentioned, you will then need to start off a build to trigger the cleanup of the older builds. The build may fail again due to lack of free space but the post-build cleanup should now run and discard the older builds.

4

Go to Configure in your project.

1

From Jenkins Scriptler console run the below groovy script to delete all the builds of jobs listed under a view

import jenkins.model.Jenkins

hudson.model.Hudson.instance.getView('<ViewName>').items.each() {
  println it.fullDisplayName


def jobname=it.fullDisplayName
def item = hudson.model.Hudson.instance.getItem(jobname)
def build = item.getLastBuild()
if (item.getLastBuild() !=null)
  {
Jenkins.instance.getItemByFullName(jobname).builds.findAll { it.number <= build.getNumber() }.each { it.delete() }

}
}
-1

Actually I think that isn't really good to delete folders by yourself.

Let specialists do. Did you try Discard Old Builds Plugin yet?

"You can configure how to discard builds in more detail than the default 'Discard Old Build' function. Other than # of builds and days, you can specify build status to discard/keep. For older builds, you can configure interval to keep builds (once in a month, once in ten builds...). You can also use logfile size to decide if delete a old build."

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.