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?

r.rodriguez
  • 907
  • 2
  • 9
  • 12

6 Answers6

55

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.

jwernerny
  • 6,978
  • 2
  • 31
  • 32
  • 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 '14 at 05: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 https://wiki.jenkins-ci.org/display/JENKINS/Configuration+Slicing+Plugin – Allen Rice Feb 11 '16 at 18:48
  • 1
    @jwernerny Once you've ticked that, how do you force it to do the discard operation? – Carlos Oct 27 '17 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 '17 at 17:26
  • The jenkins UI no longer lists this option. Please update your answer. – Harry Moreno Apr 10 '18 at 21:43
  • @HarryMoreno - Just checked in Jenkins 2.117, and the option "Discard Old Builds" is still on the Project Configuration page. (2nd item on the page, just after the Description box.) – jwernerny May 07 '18 at 18:22
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

mkobit
  • 43,979
  • 12
  • 156
  • 150
shusson
  • 5,542
  • 34
  • 38
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.

Robert Hunt
  • 7,914
  • 5
  • 40
  • 43
4

Go to Configure in your project.

Community
  • 1
  • 1
Anuja Lamahewa
  • 897
  • 1
  • 11
  • 23
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() }

}
}
Manthan Dave
  • 2,137
  • 2
  • 17
  • 31
Manoj
  • 11
  • 3
-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."

rodrigocprates
  • 498
  • 6
  • 22