Hi I want to make a script that lets me easily view my circle ci logs programmatically of failed jobs. I have a working script for the v1.1 circle ci, but I can't get this working for the v2 api.
Does anyone have a v2 url that replaces this and contains the log_url
value?
step_data=$(curl -s -H "Circle-Token: $CIRCLE_CI_TOKEN" \
".1/project/$platform/$org/$repo/$job_number")
Heres the full script for reference
#!/bin/bash
set -ex
platform="github"
org="myorgname"
repo="myrepo"
branch="mybranchname"
# Get the latest pipeline
pipeline_id=$(curl -s -H "Circle-Token: $CIRCLE_CI_TOKEN" \
"/$platform/$org/$repo/pipeline?branch=$branch" | jq -r '.items[0].id')
# Get the latest workflow
workflow_id=$(curl -s -H "Circle-Token: $CIRCLE_CI_TOKEN" \
"/$pipeline_id/workflow" | jq -r '.items[0].id')
# Get failed job number and job UUID
job_data=$(curl -s -H "Circle-Token: $CIRCLE_CI_TOKEN" \
"/$workflow_id/job")
job_number=$(echo "$job_data" | jq -r '.items[] | select(.status=="failed") | .job_number')
job_uuid=$(echo "$job_data" | jq -r '.items[] | select(.status=="failed") | .id')
if [ -z "$job_number" ]; then
echo "❌ No failed jobs found in workflow $workflow_id"
exit
fi
echo "