Jenkins Agent "No space left on device" - Fix Disk Exhaustion
A step could not write because the agent’s disk is full. Workspaces, Docker images/layers, and old build data accumulate until a write fails with ENOSPC, killing the build partway through.
What this error means
A build fails with No space left on device (or write error: No space left on device) during checkout, build, or a Docker step. df -h on the agent shows the workspace or Docker volume at or near 100%.
fatal: write error: No space left on device
# or from a Docker build
failed to copy files: write /var/lib/docker/...: no space left on deviceCommon causes
Workspaces and old builds not cleaned
Many jobs leave large workspaces, and undiscarded build history/artifacts accumulate on the agent and controller until the disk fills.
Docker images and layers piling up
Repeated docker build/pull on a long-lived agent fills /var/lib/docker with dangling images, layers, and build cache that nothing prunes.
How to fix it
Clean the workspace and prune Docker
Free space as part of the pipeline or on the agent host.
cleanWs() // Workspace Cleanup plugin, in post {}
sh 'docker system prune -af --volumes' // reclaim image/layer/cache spaceBound retention and use ephemeral agents
- Add "Discard old builds" so artifacts/logs do not accumulate indefinitely.
- Run builds on ephemeral (container/cloud) agents that start with a clean disk.
- Schedule
docker system pruneand stale-workspace cleanup on persistent agents.
How to prevent it
- Add
cleanWs()and "Discard old builds" to every heavy job. - Prefer ephemeral agents so disk never accumulates across builds.
- Monitor agent disk and prune Docker on a schedule.