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:
parent
cae69ca3ec
commit
296508575a
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue