diff --git a/helpers.sh b/helpers.sh index b15fedb3..1ffc8e5e 100644 --- a/helpers.sh +++ b/helpers.sh @@ -639,6 +639,24 @@ deploy() { fold_end deploy } +retry() { + local retries=$1 + local command=$2 + local status=0 + + $command || status=$? + + if [[ $status -ne 0 ]]; then + if [[ $retries -gt 0 ]]; then + echo "Retrying in one second..." + sleep 1 + retry $(($retries - 1)) "$command" + else + print_error_and_exit "The command '${command}' failed too often (last exit code: ${status})." + fi + fi +} + ################################################################################ # Travis-related helper functions (based on https://git.io/vzcTj). diff --git a/pharo/run.sh b/pharo/run.sh index 8be54224..cab26ffe 100644 --- a/pharo/run.sh +++ b/pharo/run.sh @@ -247,7 +247,7 @@ pharo::prepare_vm() { pushd "${config_vm_dir}" > /dev/null fold_start download_vm "Downloading ${smalltalk_name} vm..." download_file "${pharo_vm_url}" "${pharo_zeroconf}" - bash "${pharo_zeroconf}" + retry 3 "bash ${pharo_zeroconf}" fold_end download_vm popd > /dev/null fi @@ -283,7 +283,7 @@ pharo::prepare_image() { pushd "${target}" > /dev/null fold_start download_image "Downloading ${smalltalk_name} image..." download_file "${pharo_image_url}" "${pharo_zeroconf}" - bash "${pharo_zeroconf}" + retry 3 "bash ${pharo_zeroconf}" fold_end download_image popd > /dev/null fi