cicd workspace ai_generated true

java.io.IOException: The workspace is already in use by another build

ID: cicd/jenkins-workspace-locked

Also available as: JSON · Markdown
86%Fix Rate
87%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
any active

Root Cause

Jenkins cannot start a build because the workspace directory is locked by another running or stuck build. Concurrent builds of the same job compete for the same workspace directory.

generic

Workarounds

  1. 88% success Enable custom workspace paths or use workspace cleanup plugin
    Add 'customWorkspace "${WORKSPACE}-${BUILD_NUMBER}"' in the pipeline agent block to give each build its own workspace, or use the Workspace Cleanup plugin to clean up before each build
  2. 85% success Configure concurrent builds with separate workspaces using the throttle-concurrents plugin
    Install the Throttle Concurrent Builds plugin, configure a throttle category, and set maximum concurrent builds. Jenkins will automatically create workspace@2, workspace@3, etc. for concurrent runs

Dead Ends

Common approaches that don't work:

  1. Manually delete the workspace directory while a build is running 70% fail

    Deleting the workspace of a running build causes that build to fail mid-execution with file-not-found errors

  2. Kill all Java processes on the agent to release locks 75% fail

    Killing the agent process disconnects it from Jenkins, orphans child processes, and may corrupt build state

Error Chain

Leads to:
Preceded by:
Frequently confused with: