nomad alloc logs: Read Nomad Task Logs in CI
nomad alloc logs prints or follows the stdout (or stderr) of a task within an allocation.
When a deploy fails, the task logs explain why. alloc logs fetches them by allocation ID, or by job with -job for the latest alloc.
What it does
nomad alloc logs streams the log output of a specific task in an allocation. By default it prints stdout; -stderr switches to stderr. -f follows live, and -tail with -n limits how much history is shown.
Common usage
nomad alloc logs 8d5d <task>
nomad alloc logs -stderr 8d5d <task>
nomad alloc logs -f -tail -n 100 8d5d <task>
# resolve the latest alloc for a job automatically
nomad alloc logs -job webOptions
| Flag | What it does |
|---|---|
| -stderr | Show stderr instead of stdout |
| -f | Follow the log output (stream) |
| -tail | Show the tail of the log (with -n for line count) |
| -n <num> | Number of trailing lines to show |
| -job <name> | Use the latest allocation of a job by name |
| -task <name> | Select the task when the alloc has several |
In CI
After a failed nomad job run, pipe nomad alloc logs -stderr -job <name> into the build output so the failure cause shows up in the pipeline log. Avoid -f in CI unless you also bound it, or the step never exits.
Common errors in CI
"No allocation(s) with prefix or id ... found" means a wrong or expired alloc ID; list current allocs with nomad job status. "Error: task name required" means the allocation runs multiple tasks; add the task name or -task. "Failed to retrieve logs" can mean the node running the alloc is down so the logs are unreachable.