Jenkins: your Jenkins data directory is almost full and automated disk cleanup
Tags: jenkins
Published: 2019-03-28 18:18:17

---
title: Jenkins: your Jenkins data directory is almost full and automated disk cleanup
published: true
tags: Jenkins
canonical_url: https://rtfm.co.ua/en/jenkins-your-jenkins-data-directory-is-almost-full-and-automated-disk-cleanup/
---

![](https://rtfm.co.ua/wp-content/uploads/2016/01/Jenkins.sh-600x600-e1453134979914.png)We have a Jenkins instance with a bunch of jobs.

After a while – a new warning appeared:

> Jenkins: your Jenkins data directory /var/lib/jenkins (aka JENKINS\_HOME) is almost full

Checked disk usage with the [`ncdu`](https://rtfm.co.ua/linux-ncdu-i-pydf-otobrazhenie-informacii-o-zanyatom-svobodnom-meste-na-diskax/) and found few jobs which used really lot of space:

```
root@jenkins-production:/data/jenkins# du -h --max-depth 1 jobs/
..
25G     jobs/APITests
...
```

And mainly space is used by a job’s logs:

```
root@jenkins-production:/data/jenkins# ls -lh /data/jenkins/jobs/APITests/jobs/Projectname/jobs/Stage/jobs/ProjectnameStageAPItests/builds/551/log
-rw-r--r-- 1 root root 77M Mar  1 12:49 /data/jenkins/jobs/APITests/jobs/Projectname/jobs/Stage/jobs/ProjectnameStageAPItests/builds/551/log
```

There is a lot of old builds and each keeps its log.

The simplest way to solve this issue is to enable the _Discard Old Builds_ option in a job’s config:

[![](https://rtfm.co.ua/wp-content/uploads/2019/03/Screenshot_20190326_112939-1.png "Jenkins: your Jenkins data directory is almost full и автоматическая очистка диска")](https://rtfm.co.ua/wp-content/uploads/2019/03/Screenshot_20190326_112939-1.png)

Apparently, it was added in Jenkins v2.х, as previously I remember had to manually describe a workspace cleanup in a Jenkinsfiles.

Check disk used now:

```
root@jenkins-production:/data/jenkins# du -h --max-depth 1 jobs/APITests/jobs/Projectname/
23G     jobs/APITests/jobs/Projectname/jobs
23G     jobs/APITests/jobs/Projectname/
```

Save new settings, run a new build and check disk after it:

```
root@jenkins-production:/data/jenkins# du -h --max-depth 1 jobs/APITests/jobs/Projectname/
7.0G    jobs/APITests/jobs/Projectname/jobs
7.0G    jobs/APITests/jobs/Projectname/
```

Also, there is the [Discard Old Build](https://plugins.jenkins.io/discard-old-build) plugin which allows to configure the cleanup process more accurately.

### Similar posts

- <small>02/09/2017</small> [Azure: подключение дополнительного диска к VM и миграция Jenkins](https://rtfm.co.ua/azure-podklyuchenie-dopolnitelnogo-diska-k-vm-i-migraciya-jenkins/)<small> (0)</small>   
- <small>02/08/2017</small> [Jenkins: sandbox.RejectedAccessException: Scripts not permitted to use](https://rtfm.co.ua/jenkins-sandbox-rejectedaccessexception-scripts-not-permitted-to-use/)<small> (0)</small>  
- <small>03/13/2019</small> [Jenkins: import a job to another server](https://dev.to/setevoy/jenkins-import-a-job-to-another-server-1dg)<small> (0)</small>  
- <small>03/19/2019</small> [Jenkins: Scripted Pipeline – Production environment job confirmation step](https://dev.to/setevoy/jenkins-scripted-pipeline--production-environment-job-confirmation-step-39e0)<small> (0)</small>