Deleting Old Builds - Best Strategy for Cleanup and disk space management

Issue

  • Jenkins builds can pile up and cause disk space to grow out of control
  • Performance issues can result in large/complex instances with large number of projects building frequently, such as slowdown of the GUI as it attempts to load the job history, etc.
  • Configuring build cleanup following project setup can be manual and time-consuming process, especially with large number of projects

Environment

  • CloudBees Jenkins Enterprise

Resolution

There are a number of ways to manage build cleanup:
1) By default, you can enable the “Discard Old Builds” in each project/job’s configuration page.
This will perform basic cleanup, using functionality found in Jenkins core. To make this bulk change to large number of projects
(if you have large number of projects and it’s not feasible to do this individually to each one), please install/use the
Configuration Slicing Plugin

2) You can install/use the Discard Old Build plugin
to do the cleanup. This will extend the basic Jenkins “Discard Old Builds” functionality in each build/project’s configuration,
providing additional options.

3) If you have large number of existing builds and it’s not feasible to manually cleanup builds using one of the options above, it’s
possible to perform manual cleanup of jobs from the filesystem (in $JENKINS_HOME/jobs). Navigate to $JENKINS_HOME/jobs/<jobname>/builds
folder for each project, and delete some or all of the files inside here (which comprise the build history). Following the deletion, it
will be necessary to restart Jenkins or “Reload Configuration from Disk” (both in “Manage Jenkins”) so the links to the deleted
builds will disappear.
Following this operation, install/use the Configuration Slicing Plugin
mentioned in step #1 so you don’t need to perform this bulk deletion again in the future.

It’s also possible to purge selectively from the filesystem using “find $dir -mtime +$age -rm” where age is the oldest date
you want to keep the build (in days). This will get rid of the builds and the links. Again, you may have to restart or reload
once this is done in order for the GUI to show that the builds are no longer available. Be sure to backup your $JENKINS_HOME
(or at least the jobs folder) prior to doing this…just in case of unintentional deletes.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.