Retry git clone in scripts

Sometimes git cloning fails while trying to unittest
or build an image. This patch adds a function that
retries the clone on failure five times, waiting five
seconds between attempts.

Change-Id: I179ee242eafcad508f99c09f0aaab9f4b4ee054b
This commit is contained in:
Ed Cranford 2015-03-24 10:09:46 -05:00
parent cae69ca3ec
commit 296508575a
6 changed files with 22 additions and 7 deletions

View File

@ -157,3 +157,18 @@ function test_public_repo () {
fi
return 0
}
function git_clone_with_retry () {
local GIT_REPO=$1
local DESTINATION=$2
shift; shift
local SINGLEBRANCH=$1
RETRIES=0
until [ $RETRIES -ge 5 ]; do
rm -rf $DESTINATION
PRUN git clone $SINGLEBRANCH $GIT_REPO $DESTINATION && break
RETRIES=$[$RETRIES+1]
sleep 5
done
}

View File

@ -111,7 +111,7 @@ if [ -d "$APP_DIR/build" ] ; then
fi
fi
else
PRUN git clone $GIT $APP_DIR/build
git_clone_with_retry $GIT $APP_DIR/build
fi
# If languagepack is 'auto', build the application slug

View File

@ -55,7 +55,7 @@ TMP_LP_DIR=/tmp/apps/$TENANT/$GIT_CHECKSUM
PRUN mkdir -p $TMP_LP_DIR
TLOG ===== Cloning repo
PRUN git clone $GIT $TMP_LP_DIR/build
git_clone_with_retry $GIT $TMP_LP_DIR/build
[[ $? != 0 ]] && TLOG Git clone failed. Check repo $GIT && exit 1
if [ -d "$TMP_LP_DIR/build" ] ; then

View File

@ -117,11 +117,11 @@ if ! (test_public_repo $GIT); then
fi
if [[ $COMMIT_SHA ]]; then
PRUN git clone $GIT $APP_DIR/code
git_clone_with_retry $GIT $APP_DIR/code
cd $APP_DIR/code
PRUN git checkout -B solum_testing $COMMIT_SHA
else
PRUN git clone --single-branch $GIT $APP_DIR/code
git_clone_with_retry $GIT $APP_DIR/code --single-branch
cd $APP_DIR/code
fi

View File

@ -78,11 +78,11 @@ if ! (test_public_repo $GIT); then
fi
if [[ $COMMIT_SHA ]]; then
PRUN git clone $GIT $APP_DIR/code
git_clone_with_retry $GIT $APP_DIR/code
cd $APP_DIR/code
PRUN git checkout -B solum_testing $COMMIT_SHA
else
PRUN git clone --single-branch $GIT $APP_DIR/code
git_clone_with_retry $GIT $APP_DIR/code --single-branch
cd $APP_DIR/code
fi

View File

@ -39,7 +39,7 @@ PRUN mkdir -p $APP_DIR
add_ssh_creds "$GIT_PRIVATE_KEY" "$APP_DIR"
[[ -d $APP_DIR/build ]] && rm -rf $APP_DIR/build
PRUN git clone $GIT $APP_DIR/build
git_clone_with_retry $GIT $APP_DIR/build
remove_ssh_creds "$GIT_PRIVATE_KEY"