diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/ci/scripts/init.sh | 97 |
1 files changed, 28 insertions, 69 deletions
diff --git a/tools/ci/scripts/init.sh b/tools/ci/scripts/init.sh index f427be910..4b0764488 100755 --- a/tools/ci/scripts/init.sh +++ b/tools/ci/scripts/init.sh @@ -12,6 +12,29 @@ function do_init { check_error $? } +retry_with_increasing_wait() +{ + local wait_time=1 + + while true; do + "$@" + local retval=$? + + if [[ $retval -eq 0 || $wait_time -gt 16 ]]; then + break + fi + + printf "command %s failed (exit code %d), waiting %d seconds until next try.\n"\ + "$*" "$retval" "$wait_time" + + sleep "$wait_time" + # 1, 2, 4, 8, 16... + (( wait_time = 2 * wait_time )) + done + + return "$retval" +} + function update_repos { if [ "$RUNFROMSHELL" != "" ]; then @@ -35,27 +58,8 @@ function aptget_update { return fi echo "apt-get update" - apt-get update - if [ "$?" != 0 ]; then - sleep 1s - apt-get update - if [ "$?" != 0 ]; then - sleep 2s - apt-get update - if [ "$?" != 0 ]; then - sleep 5s - apt-get update - if [ "$?" != 0 ]; then - sleep 10s - apt-get update - if [ "$?" != 0 ]; then - sleep 15s - apt-get update - fi - fi - fi - fi - fi + + retry_with_increasing_wait apt-get update } function aptget_install { @@ -66,31 +70,10 @@ function aptget_install { fi update_repos - aptget_update + retry_with_increasing_wait aptget_update echo "apt-get -y -qq install $*" - apt-get -y -qq install $* - if [ "$?" != 0 ]; then - sleep 1s - apt-get -y -qq install $* - if [ "$?" != 0 ]; then - sleep 2s - apt-get -y -qq install $* - if [ "$?" != 0 ]; then - sleep 5s - apt-get -y -qq install $* - if [ "$?" != 0 ]; then - sleep 10s - aptget_update - apt-get -y -qq install $* - if [ "$?" != 0 ]; then - sleep 15s - apt-get -y -qq install $* - fi - fi - fi - fi - fi + retry_with_increasing_wait apt-get -y -qq install "$@" } function gitclone1 { @@ -109,31 +92,7 @@ function gitclone { export name2=${CI_BUILD_REPO##*@} export name2=https://${name2%/*}/$2 - gitclone1 "$name1" "$name2" - if [ "$?" != 0 ]; then - sleep 1s - gitclone1 "$name1" "$name2" - if [ "$?" != 0 ]; then - sleep 3s - gitclone1 "$name1" "$name2" - if [ "$?" != 0 ]; then - sleep 5s - gitclone1 "$name1" "$name2" - if [ "$?" != 0 ]; then - sleep 10s - gitclone1 "$name1" "$name2" - if [ "$?" != 0 ]; then - sleep 15s - gitclone1 "$name1" "$name2" - if [ "$?" != 0 ]; then - sleep 20s - gitclone1 "$name1" "$name2" - fi - fi - fi - fi - fi - fi + retry_with_increasing_wait gitclone1 "$name1" "$name2" check_error $? } |