REST API /repos/{owner}/{repo}/actions/runs/{run_id}/attempts/{attempt_number}/logs returns 404 while workflow run is still running
#75518
Replies: 223 comments 6 replies
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
👍 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
Any update ? |
Beta Was this translation helpful? Give feedback.
-
|
hallo |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+20k |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
Yeah, this is expected behavior. The logs API usually returns a 404 while the workflow or job is still running — logs are only available once the run is complete. Would be great if GitHub supported partial or live logs, but as of now, we just have to wait for it to finish. |
Beta Was this translation helpful? Give feedback.
-
|
This is a timing issue with the GitHub Actions API. The logs endpoint returns 404 because logs aren't immediately available during workflow execution. Here's the solution: Root Cause
Solution 1: Wait for Completion# Poll until workflow completes
while true; do
status=$(curl -s -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID" | \
jq -r '.status')
if [[ "$status" == "completed" ]]; then
# Now logs are available
curl -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/attempts/1/logs"
break
fi
echo "Status: $status, waiting..."
sleep 30
doneSolution 2: Use Job-Level Logs (More Reliable)Get individual job logs instead of run logs# 1. Get jobs for the run
curl -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/jobs" | \
jq -r '.jobs[].id'
# 2. Get logs for specific job (works during execution)
curl -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/jobs/$JOB_ID/logs"
Solution 3: Real-Time Streaming (Advanced)import requests
import time
def stream_workflow_logs(owner, repo, run_id, token):
headers = {"Authorization": f"token {token}"}
while True:
# Check run status
run_response = requests.get(
f"https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}",
headers=headers
)
if run_response.json()["status"] == "completed":
# Get final logs
logs_response = requests.get(
f"https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}/logs",
headers=headers
)
return logs_response.content
# Get job logs during execution
jobs_response = requests.get(
f"https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}/jobs",
headers=headers
)
for job in jobs_response.json()["jobs"]:
if job["status"] in ["in_progress", "completed"]:
job_logs = requests.get(
f"https://api.github.com/repos/{owner}/{repo}/actions/jobs/{job['id']}/logs",
headers=headers
)
if job_logs.status_code == 200:
print(f"Job {job['name']} logs available")
time.sleep(10)Solution 4: GitHub CLI Alternative# Real-time log following
gh run view $RUN_ID --log
# Or watch specific job
gh run view $RUN_ID --job=$JOB_ID --logAPI Behavior Summary
Workaround for Your Use Case# Robust script that handles the timing issue
get_workflow_logs() {
local run_id=$1
local max_attempts=60 # 30 minutes max wait
local attempt=0
while [ $attempt -lt $max_attempts ]; do
# Try the run logs endpoint
if curl -sf -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/logs" \
-o "logs_$run_id.zip"; then
echo "Logs downloaded successfully"
return 0
fi
# Fall back to job logs if run logs not ready
curl -s -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/jobs" | \
jq -r '.jobs[].id' | while read job_id; do
curl -s -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/jobs/$job_id/logs" \
>> "partial_logs_$run_id.txt"
done
sleep 30
((attempt++))
done
}The 404 is expected behavior - you need to handle the timing appropriately. |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
UP |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Bug
Body
It is impossible to receive the logs of a workflow-run that is in-progress because of that reason.
Also using https://api.github.com/repos/OWNER/REPO/actions/jobs/JOB_ID/logs for getting a specific job logs it returns 404 while the job is running.
Beta Was this translation helpful? Give feedback.
All reactions