CI/CDMedium
Fix: Jenkins Pipeline Timeout
Jenkins build shows 'Cancelling nested steps due to timeout'
!Symptoms
- Jenkins build shows 'Cancelling nested steps due to timeout'
- Pipeline stuck for hours with no progress
- Build marked as ABORTED after timeout period
- Agent goes offline during long builds
?Root Causes
- Test suite hanging on a specific test (deadlock, infinite loop)
- Waiting for user input in a non-interactive pipeline
- Agent ran out of disk space during build
- Network issue causing downloads to hang
- Docker build stuck on a layer (e.g., large dependency install)
#Diagnosis Steps
- 1Check the Jenkins console output to see which step was running when timeout occurred
- 2Look at the agent system resources (disk, memory, CPU) during the build
- 3Check for `input` steps that might be waiting for approval
- 4Review the test logs for the last test that ran before the hang
- 5Check network connectivity from the agent to external resources
>Fix
- 1Add explicit timeouts to pipeline stages: `timeout(time: 30, unit: 'MINUTES') { ... }`
- 2Kill the stuck process on the agent and retry
- 3Free disk space on the agent: clean workspace, docker prune
- 4Fix the hanging test (deadlock, missing mock, blocking I/O)
- 5Use `options { timeout(time: 1, unit: 'HOURS') }` at the pipeline level
*Prevention
- Set stage-level timeouts for each critical step
- Set a global pipeline timeout as a safety net
- Monitor agent health (disk, memory) and alert on low resources
- Run tests with a timeout per test case (e.g., JUnit timeout annotation)
- Clean workspace before each build: `cleanWs()` post step
Related Error Messages
Cancelling nested steps due to timeoutBuild timed outABORTEDAgent went offlineCannot contact agent