Skip to content

Commit eaf9924

Browse files
chore(ci) retry build 3 times before failing (#1166)
1 parent ec2fcc0 commit eaf9924

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
- name: Grant execute permission for gradlew
2424
run: chmod +x gradlew
2525
- name: Build with Gradle
26-
run: ./gradlew build
26+
run: scripts/retry.sh 3 "./gradlew clean build"

scripts/retry.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# Usage: retry.sh <max_tries> <command to run>
3+
4+
readonly max_tries=$1
5+
readonly command="${@: 2}"
6+
attempts=0
7+
return_code=1
8+
while [[ $attempts -lt $max_tries ]]; do
9+
((attempts++))
10+
if [[ attempts -gt 1 ]]; then sleep 10; fi
11+
echo "RETRY: Attempt $attempts of $max_tries."
12+
$command && break
13+
done
14+
15+
return_code=$?
16+
17+
if [[ $return_code == 0 ]]; then
18+
echo "RETRY: Attempt $attempts succeeded."
19+
else
20+
echo "RETRY: All $attempts attempts failed."
21+
fi
22+
23+
exit $return_code

0 commit comments

Comments
 (0)