Jenkins Workspace Delete Failures from Stale Lock Files: A Diagnostic Guide
Build fails with java.io.IOException: Unable to delete workspace due to a stale .lock left by an interrupted build. This guide shows how to confirm no active executor, locate the lock, safely remove it, verify cleanup, and escalate when locks persist.
16 Feb 2026, 07:00 UTC

Problem and takeaway
A Jenkins build aborts during cleanup with java.io.IOException: Unable to delete workspace. The build log shows workspace deletion failure and subsequent steps are skipped. In practice this is most often a stale lock left by an interrupted build, not a disk problem. The useful first check is whether any executor is actually using the workspace and whether a .lock file is present with an old timestamp.
Recognizable condition
The failure appears at the end of a build or at the start of the next run when Jenkins tries to clean or recreate the workspace. The job may be freestyle or Pipeline, and the error is consistent across retries until the lock is cleared. The workspace directory exists on the controller or agent filesystem under $JENKINS_HOME/jobs//builds//workspace.
Cause to symptom table
| Symptom | Typical cause | Diagnostic clue |
|---|---|---|
| Unable to delete workspace, IOException on cleanup | Stale .lock from interrupted build | .lock file timestamp older than last build start, no active executor |
| Lock reappears after removal | Stuck executor or concurrent build holding lock | Executors view shows busy, thread dump contains WorkspaceCleanup |
| Permission denied on workspace | Wrong file ownership after agent restart or manual change | ls -l shows owner not jenkins user |
Note on version assumptions: lock file location changed over time. In older layouts the lock lived under workspace/.lock. In Jenkins 2.303+ the lock is often under the build directory. Adjust the path you inspect to match the installed version.
Ordered checks
Confirm no active build is using the workspace. Run on the Jenkins controller UI: Manage Jenkins → Nodes and Clouds → Executors. Verify the job is not listed as building on any executor. Also check the job’s build queue. Do not proceed with file changes while a build is running; removing a lock during an active build risks data loss.
Locate and inspect the lock file. Run on the Jenkins controller host as the user that owns the Jenkins process, typically jenkins. Use a placeholder for job and build.
ls -l $JENKINS_HOME/jobs/<job-name>/builds/<build-number>/workspace/.lockExpected check: file exists, timestamp is older than the last successful build start, and size is small. If the path is empty, try the build directory variant:
find $JENKINS_HOME/jobs/<job-name>/builds/<build-number> -maxdepth 1 -name '.lock' -lsRisk: reading only is safe. Do not delete yet.
Check ownership and permissions.
stat $JENKINS_HOME/jobs/<job-name>/builds/<build-number>/workspaceExpected check: owner matches Jenkins runtime user and directory is writable. Mismatched ownership explains delete failures even without a lock.
Check for concurrent builds. In the job configuration, verify if multiple executors are allowed and if the pipeline uses lockable resources. Look for parallel stages that may hold the workspace.
Fixes tied to findings
Stale lock, no active executor
Rename the lock to preserve evidence before removal.
mv $JENKINS_HOME/jobs/<job-name>/builds/<build-number>/workspace/.lock $JENKINS_HOME/jobs/<job-name>/builds/<build-number>/workspace/.lock.bak.$(date +%s)Then trigger a clean build from the UI with the option Delete workspace before build. If you must restart, use a safe restart from a machine with jenkins-cli access:
jenkins-cli safe-restartRequired permission: OS write access to $JENKINS_HOME and Jenkins CLI access. Risk: if a build starts between check and rename, workspace corruption can occur.
Wrong ownership
Restore ownership to the Jenkins user. Replace <jenkins-user> with the actual runtime user.
chown -R <jenkins-user>:<jenkins-group> $JENKINS_HOME/jobs/<job-name>/builds/<build-number>/workspaceRisk: recursive chown on a large workspace is slow and can interfere with running builds.
Concurrent build holding lock
Do not remove the lock. Cancel or wait for the competing build to finish, then retry cleanup. If the job is configured for concurrent builds, disable it temporarily for this job.
Verification
- Trigger a new build and confirm the build log contains Finished: SUCCESS and no IOException on workspace deletion.
- Check the Jenkins log for absence of Unable to delete workspace messages.
- Use the UI Executors view to ensure no stuck executors remain after the run.
Limitations: This guide addresses lock-related deletion failures only. Disk full, NFS stale handles, or agent filesystem permission issues produce similar errors but require different remediation.
Escalation criteria
Escalate if the lock reappears immediately after removal, or if builds continue to fail with IOException after ownership is corrected. Collect a thread dump from Manage Jenkins → Thread Dump and look for threads blocked on workspace cleanup or file deletion. Also check for plugins that manage workspace locks, such as Workspace Cleanup Plugin or Lockable Resources Plugin, for misconfiguration.
Prevention
Enable a quiet period for the job to reduce overlapping starts. In Pipeline, use exclusive build locks to serialize access to a shared workspace:
lock('workspace-<job-name>') {Configure the Workspace Cleanup Plugin to clean before build rather than after, and avoid manual edits to $JENKINS_HOME while Jenkins is running.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.