What's Actually Happening

Jenkins builds hang in queue or during execution. Jobs show "Pending" or "Running" indefinitely without progress, blocking the pipeline.

The Error You'll See

Build stuck in queue:

```bash curl -s http://localhost:8080/queue/api/json | jq .items[].task.name

my-job (waiting for executor) ```

Build hanging during execution:

```bash curl -s http://localhost:8080/computer/api/json | jq .computer[].idle

false ```

Console output shows nothing:

bash
Started by user admin
[Pipeline] stage
[Pipeline] { (Build)
Hangs here with no output

Why This Happens

  1. 1.No available executors - All executors busy or offline
  2. 2.Agent disconnected - Jenkins agent lost connection
  3. 3.Resource exhaustion - Disk full, memory low
  4. 4.Deadlock in pipeline - Parallel stages blocking
  5. 5.External dependency stuck - Database or API call hanging
  6. 6.Long-running build - Previous build not finishing
  7. 7.Executor hung - Executor process stuck

Step 1: Check Jenkins Queue Status

```bash curl -s http://localhost:8080/queue/api/json | jq

curl -s http://localhost:8080/queue/api/json | jq .items[] | {id: .id, name: .task.name, why: .why}

curl -s http://localhost:8080/queue/api/json | jq .items[].why

curl -s http://localhost:8080/queue/api/json | jq .items | length

curl -X POST http://localhost:8080/queue/cancel?id=123 ```

Step 2: Check Executor Availability

```bash curl -s http://localhost:8080/computer/api/json | jq .computer[] | {name: .name, idle: .idle, offline: .offline}

curl -s http://localhost:8080/computer/api/json | jq .computer[] | select(.offline == true)

curl -s http://localhost:8080/computer/api/json | jq [.computer[] | select(.idle == true)] | length

curl -s http://localhost:8080/computer/api/json | jq .computer[] | select(.idle == false) ```

Step 3: Check Agent Connectivity

```bash curl -s http://localhost:8080/computer/agent-name/api/json | jq {offline: .offline, offlineCause: .offlineCause}

cat /var/log/jenkins-agent.log

ps aux | grep jenkins-agent

ssh -p 22 jenkins@agent-host

systemctl restart jenkins-agent ```

Step 4: Check Running Builds

```bash curl -s http://localhost:8080/job/my-job/123/api/json | jq {building: .building, duration: .duration}

curl -X POST http://localhost:8080/job/my-job/123/stop

curl -X POST http://localhost:8080/job/my-job/123/kill ```

Step 5: Check Disk and Memory

```bash df -h /var/lib/jenkins

find /var/lib/jenkins/jobs -name builds -exec sh -c ls -t "$1" | tail -n +20 | xargs rm -rf _ {} \;

find /var/lib/jenkins/workspace -type d -mtime +30 -exec rm -rf {} \;

free -h

ps aux | grep jenkins | awk {print $6}

cat /etc/default/jenkins | grep JAVA_ARGS

systemctl restart jenkins ```

Step 6: Check Pipeline Deadlock

```bash curl -s http://localhost:8080/job/my-pipeline/123/wfapi/describe | jq .stages[] | {name: .name, status: .status}

curl -s http://localhost:8080/job/my-pipeline/123/wfapi/describe | jq .stages[] | select(.status == "IN_PROGRESS")

curl -X POST http://localhost:8080/job/my-pipeline/123/resume

curl -X POST http://localhost:8080/job/my-pipeline/123/stop ```

Step 7: Check External Dependencies

bash
ping -c 3 external-api
nc -zv external-api 443
nslookup external-api
curl -m 10 https://external-api/health
mysql -h db-host -u user -p -e "SELECT 1"
git ls-remote https://github.com/org/repo

Step 8: Restart Hung Executors

```bash curl -X POST http://localhost:8080/computer/agent-name/toggleOffline?reason=restart

ssh agent-host systemctl restart jenkins-agent

curl -X POST http://localhost:8080/computer/agent-name/toggleOffline?reason=back%20online

systemctl restart jenkins

curl -X POST http://localhost:8080/safeRestart ```

Step 9: Check Jenkins Logs

```bash journalctl -u jenkins -f

tail -f /var/log/jenkins/jenkins.log

grep -i "error" /var/log/jenkins/jenkins.log | tail -50

curl -s http://localhost:8080/threadDump > jenkins-threads.txt ```

Step 10: Monitor and Prevent Stuck Builds

```bash curl -s http://localhost:8080/queue/api/json | jq .items | length

curl -s http://localhost:8080/computer/api/json | jq .computer[] | {name: .name, idle: .idle}

watch -n 30 curl -s http://localhost:8080/queue/api/json | jq ".items | length" ```

Jenkins Build Stuck Checklist

CheckCommandExpected
Queue length/queue/api/jsonLow count
Executors available/computer/api/jsonIdle executors
Agents online/computer/agent/api/jsonoffline: false
Disk spacedf -h< 90% used
Memoryfree -hAvailable

Verify the Fix

```bash curl -s http://localhost:8080/queue/api/json | jq .items | length

curl -s http://localhost:8080/computer/api/json | jq [.computer[] | select(.idle)] | length

curl -X POST http://localhost:8080/job/my-job/build

curl -s http://localhost:8080/job/my-job/lastBuild/api/json | jq .building

curl -s http://localhost:8080/job/my-job/lastBuild/api/json | jq .duration ```

  • [Fix Jenkins Agent Offline](/articles/fix-jenkins-agent-offline)
  • [Fix Jenkins Pipeline Failed](/articles/fix-jenkins-pipeline-failed)