Skip to content
VA2PT.COM

Resolving Out-of-Disk Issues on a Jenkins VM

By Abhishek, . 3 min read

In shortJenkins VMs are prone to running out of disk space due to the accumulation of Docker images, old job workspaces, and extensive log files.

Introduction

Jenkins VMs are prone to running out of disk space due to the accumulation of Docker images, old job workspaces, and extensive log files. This guide provides actionable steps to mitigate and prevent such issues, ensuring continuous integration and delivery processes remain unaffected.

Introduction

Problem Statement

The Jenkins VM frequently encounters out-of-disk issues, disrupting builds and CI/CD pipelines. These issues arise from:

  • Accumulated Docker images.

  • Old or unused job workspaces.

  • Excessive and unmanaged log files.

Solution Overview

The primary solution involves cleaning up unused resources, such as Docker images, job workspaces, and logs, on a regular schedule. This ensures efficient disk utilization and prevents recurring space issues.

Step-by-Step Implementation

1. Clean Up Unused Docker Images

Remove unused or dangling Docker images that consume disk space:

docker system prune -af
  • Prune All Unused Data:
docker system prune -a --volumes

2. Remove Old Job Workspaces

Configure Jenkins to discard old builds automatically:

  • Navigate to Manage Jenkins > Configure System.

  • Set up a Discard Old Builds policy in the job configuration:

    • Max # of builds to keep: Define a limit for retained builds.

    • Days to keep builds: Specify the retention duration.

Alternatively, manually delete job directories from Jenkins workspace:

rm -rf /var/lib/jenkins/workspace/<job-name>

3. Delete Unnecessary Log Files

Clear large or outdated log files:

find /var/log/jenkins -type f -name "*.log" -mtime +7 -exec rm {} \;

4. Automate Cleanup with Cron Jobs

Schedule regular cleanups using cron:

crontab -e

Add the following entries:

0 2   docker system prune -af 0 3   find /var/lib/jenkins/workspace -type d -mtime +30 -exec rm -rf {} \;

Why This Solution is Best

  • Proactive Maintenance: Regular cleanups ensure disk space is managed effectively.

  • Minimized Downtime: Prevents out-of-disk errors from disrupting Jenkins operations.

  • Ease of Implementation: Requires minimal changes to existing infrastructure.

Alternative Solutions

1. Move Workspace to Larger Storage

Relocate Jenkins workspaces to a storage system with higher capacity:

  • Attach an External Volume: Mount an external disk or network storage to Jenkins:
mount /dev/sdb1 /mnt/jenkins_workspace
  • Update Jenkins configuration to use the new workspace:

    • Navigate to Manage Jenkins > Configure System.

    • Update the Home Directory path.

Advantages:

  • Provides ample disk space.

  • Allows for scaling as needed.

2. Enable Log Rotation

Implement log rotation policies to prevent excessive log accumulation:

  1. Install logrotate:
sudo apt install logrotate
  1. Configure log rotation for Jenkins logs in /etc/logrotate.d/jenkins:

    plaintext

/var/log/jenkins/*.log { daily rotate 7 compress missingok notifempty }

Advantages:

  • Limits log file sizes.

  • Automates log management.

3. Review Resource Requests and Limits

Analyze and adjust resource requests for builds:

  • Update build scripts or Jenkins job configurations to prevent excessive disk usage.

  • Limit workspace consumption by using temporary directories for intermediate files.

Advantages:

  • Optimizes resource allocation.

  • Ensures fair usage across multiple builds.

Conclusion

Managing disk space effectively is critical for maintaining Jenkins performance. Regular cleanups of unused resources, combined with proactive measures like log rotation and resource optimization, ensure long-term stability. For larger-scale operations, relocating workspaces to more extensive storage systems provides an effective, scalable solution. Together, these strategies ensure seamless CI/CD processes in Jenkins environments

  • jenkins
  • ci/cd
  • scalability

Need a hand with 24x7 SRE & NOC?

A 30-minute call with a senior engineer. We look at your setup, name the biggest risks and outline what we would do first.