highFoundationSymptom-first#workspace#locked#concurrent#executor

Jenkins workspace locked - concurrent build conflict

Build fails with 'Workspace is locked by another build'

Likely source:availabilityconfiguration

Focused incident mode — strips away everything but this runbook.

Symptoms

  • Build fails with 'Workspace is locked by another build'
  • Build stuck in 'Waiting for workspace' state
  • Jenkins log shows 'Could not allocate workspace - already in use'

When concurrentBuild is false, each build takes exclusive ownership of the workspace. If a build is killed (not aborted), the workspace lock may not be released - requiring manual cleanup.

Evidence to grab

Collect these artifacts before you change anything — they prove (or rule out) each cause.

  • Job concurrency configuration

    curl -s -u <USER>:<TOKEN> '<JENKINS_URL>/job/<JOB>/api/json?tree=concurrentBuild'
  • Workspace lock status

    curl -s -u <USER>:<TOKEN> '<JENKINS_URL>/job/<JOB>/api/json?tree=assignedLabel,workspace[name]'

Diagnostic flow

Run the steps in order, marking each claim confirmed or refuted. The evidence you gather feeds the ranked causes below.

Guided decision tree is ready.

Steps with commands, expected output, and pass/fail branches.

Ranked root causes

Evidence checklist

  • Build A is running, Build B is queued waiting for the workspace
  • Job config shows concurrentBuild: false

Confirm before fixing

curl -s -u <USER>:<TOKEN> '<JENKINS_URL>/job/<JOB>/api/json?tree=builds[number,result,building]' | python3 -c 'import sys,json; [print(b) for b in json.load(sys.stdin)["builds"] if b["building"]]'
READ

Find the currently running build

Fix

curl -s -u <USER>:<TOKEN> -X POST '<JENKINS_URL>/job/<JOB>/configSubmit' -d 'concurrentBuild=true'
CHANGE

Enable concurrent builds (or increase agent executors)

Resolution runbook

Apply from top to bottom after the cause is confirmed. Review every command before running it — risk tags are shown on each.

1
curl -s -u <USER>:<TOKEN> '<JENKINS_URL>/job/<JOB>/api/json?tree=concurrentBuild'
READ

Check concurrent build setting

2
curl -s -u <USER>:<TOKEN> '<JENKINS_URL>/computer/<AGENT>/api/json?tree=numExecutors'
READ

Check executor count

3
curl -s -u <USER>:<TOKEN> '<JENKINS_URL>/job/<JOB>/api/json?tree=builds[number,result,building]' | python3 -c 'import sys,json; [print(b) for b in json.load(sys.stdin)["builds"] if b["building"]]'
READ

Find the currently running build

4
curl -s -u <USER>:<TOKEN> -X POST '<JENKINS_URL>/job/<JOB>/stop'
DESTRUCTIVE

Stop the blocking build if safe to do so

Prevention

  • Enable concurrent builds for jobs that can safely run in parallel.
  • Increase the executor count on agents to at least 2 for concurrent jobs.
  • Use the Workspace Cleanup plugin to clean up after builds.
  • Use unique custom workspaces for jobs that must share an agent.

Commands marked READ CHANGE DESTRUCTIVE — never run DESTRUCTIVE commands against production data you cannot restore. Copy → verify → execute.