Created
September 10, 2025 04:57
-
-
Save projectgus/b270618857b75261908464b43632cdc6 to your computer and use it in GitHub Desktop.
Quick bash script to retry a GitHub Actions Workflow until any job's log matches a regular expression
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
| #!/bin/bash | |
| # | |
| # Example usage: gh_retry_until_match.sh 17581401448 "NOT successful" | |
| set -euxo pipefail | |
| while [ 1 ]; do | |
| echo "Waiting for any \"$1\" job with log output matching \"$2\"..." | |
| # Wait until the run shows a conclusion (i.e. not queued or in_progress) | |
| while ! gh run view "$1" --json conclusion -q .conclusion | grep -E '.+'; do | |
| sleep 15 | |
| done | |
| # Get the logs and grep for the result | |
| if gh run view "$1" --log | grep -E "$2"; then | |
| echo "Got it!" | |
| exit 0 | |
| fi | |
| echo "Not found, will re-run jobs..." | |
| sleep 20 | |
| gh run rerun "$1" | |
| sleep 180 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment