| name | fetching-circleci-logs |
| description | Fetches CircleCI job logs via the v1.1 API and displays step-level output. Focuses on failed steps. Use when: CI checks fail on a PR, user shares a CircleCI job URL, user asks to check build logs, 'circleci', 'build failed', 'CI failed', 'check the logs'. |
Fetching CircleCI Logs
Fetch step-level build logs from CircleCI jobs using the v1.1 API.
When to use
- PR checks failed and you need to see why
- User shares a CircleCI URL (e.g.
https://circleci.com/gh/org/repo/169955)
- User asks to investigate a CI failure
Extract job details from URL
CircleCI URLs follow this pattern:
https://circleci.com/gh/{org}/{repo}/{job_number}
Extract org, repo, and job_number from the URL. If the user provides only a job number, ask for the org/repo or check the current git remote:
git remote get-url origin | sed -E 's|.*github\.com[:/]([^/]+)/([^/.]+).*|\1/\2|'
Fetch logs
Step 1: Get the CircleCI token
grep 'token' ~/.circleci/cli.yml | awk '{print $2}'
If the file doesn't exist or has no token, tell the user to run circleci setup or set the token manually.
Step 2: Fetch job data and display step output
Run this as a single command, substituting {org}, {repo}, and {job_number}:
TOKEN=$(grep 'token' ~/.circleci/cli.yml | awk '{print $2}') && \
curl -s -H \
| \
python3 -c