timeout Command Reference for CI Scripts
timeout runs a command and kills it if it exceeds a time limit.
timeout is the guard against a single stuck command hanging an entire job until the much longer CI-level timeout fires. It is essential around network waits and follows.
Common flags/usage
- timeout DURATION CMD: e.g. timeout 30 or timeout 5m
- -k DURATION: send SIGKILL this long after the initial signal
- -s SIGNAL: choose the signal sent on timeout (default TERM)
- --preserve-status: exit with the command\u2019s own status
- Exit 124 means the command was timed out
Example
shell
timeout 60 ./wait-for-service.sh || { echo "Service never came up"; exit 1; }
timeout -k 10 5m npm run integration-testsIn CI
timeout exits 124 when the command runs too long, which lets you detect a hang and fail with a clear message instead of waiting for the job timeout. Some processes ignore SIGTERM; add -k to follow up with SIGKILL. Wrap blocking commands like tail -f or a health-check loop in timeout so they cannot stall the runner.
Key takeaways
- timeout 124 signals the command was killed for exceeding its limit.
- Add -k to escalate to SIGKILL for processes that ignore SIGTERM.
- Wrap blocking commands like tail -f so they cannot hang the job.
Related guides
tail Command Reference for CI Scriptstail prints the last lines of input or follows a growing file in CI. Reference for -n, -f, and +N, plus the -…
set -euo pipefail Reference for CI Scriptsset -euo pipefail makes bash CI scripts fail fast. Reference for -e exit-on-error, -u unset-var, and pipefail…
trap Command Reference for CI Scriptstrap runs cleanup handlers on signals and exit in CI scripts. Reference for EXIT, ERR, and signal traps so te…
curl Command Reference for CI Scriptscurl transfers data over HTTP(S) in CI scripts. Reference for -f, -sS, -L, -o, and --retry so downloads fail…