Skip to contentSkip to conversation

Add git_retry.sh wrapper around git

PATCH New Ryan Eatmon 1 participant 1 message Jan 27, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add git_retry.sh wrapper around git

We are seeing a sporadic failure in our nightly builds due to the git clone/fetch calls timing out and erroring. These events are usually resolved by just trying the git call again, but in a scripted flow it causes a failure in that run. The git_retry.sh script solves that by allowing the git command to be retried a few times while sleeping in between.

---
 git_retry.sh          | 29 +++++++++++++++++++++++++++++
 oe-layertool-setup.sh |  4 ++--
 2 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100755 git_retry.sh
git_retry.sh new file +29 -0
new file mode 100755
index 0000000..e5ed5bb
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+let glRetries=5
+let glDelay=15
+let glExitCode=0
+
+while [ $glRetries -gt 0 ]; do
+
+    git "$@"
+
+    glExitCode=$?
+
+    if [ $glExitCode -eq 0 ]; then
+        exit
+    fi
+
+    let glRetries=$glRetries-1
+
+    if [ $glRetries -gt 0 ]; then
+        echo "git failed... remaining attempts: $glRetries"
+        sleep $glDelay
+    fi
+
+done
+
+echo "git failed... giving up..."
+
+exit $glExitCode
+
oe-layertool-setup.sh +2 -2
index df1523f..932ec49 100755
@@ -336,9 +336,9 @@ clone_repo() {
     if [ -d $sourcedir/$name ]
     then
         cd $sourcedir/$name
-        git fetch --all
+        $oebase/git_retry.sh fetch --all
     else
-        git clone $uri $sourcedir/$name
+        $oebase/git_retry.sh clone $uri $sourcedir/$name
         if [ "$?" != "0" ]
         then
             echo "ERROR: Could not clone repository at $uri"
Signature · 1 line
2.17.1