Created
September 18, 2025 08:33
-
-
Save willcl-ark/ace283a87da02b0b1c39b76925522e92 to your computer and use it in GitHub Desktop.
re-run a job using github API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e | |
| GITHUB_TOKEN="${GITHUB_TOKEN:-}" | |
| list_jobs() { | |
| local owner_repo="$1" | |
| local run_id="$2" | |
| local response | |
| response=$(curl -s \ | |
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "https://api.github.com/repos/$owner_repo/actions/runs/$run_id/jobs?per_page=100") | |
| echo "$response" | jq -r '.jobs[] | "\(.id)|\(.name)|\(.status)|\(.conclusion // "N/A")"' | while IFS='|' read -r job_id job_name status conclusion; do | |
| printf "ID: %s\n" "$job_id" | |
| printf "Name: %s\n" "$job_name" | |
| printf "Status: %s\n" "$status" | |
| printf "Conclusion: %s\n" "$conclusion" | |
| echo "----------------------------------------" | |
| done | |
| } | |
| rerun_job() { | |
| local owner_repo="$1" | |
| local job_id="$2" | |
| curl -s \ | |
| -X POST \ | |
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"enable_debug_logging": false}' \ | |
| "https://api.github.com/repos/$owner_repo/actions/jobs/$job_id/rerun" > /dev/null | |
| echo "Successfully requested re-run of job $job_id" | |
| } | |
| case "$1" in | |
| "list-jobs") | |
| list_jobs "$2" "$3" | |
| ;; | |
| "rerun") | |
| rerun_job "$2" "$3" | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment