From 4275d61b55a5496c42c80ae0f997e31dcda1d253 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Mon, 28 Sep 2020 14:54:55 -0700 Subject: [PATCH] move retry to script --- .../templates/stages/deploy-stage.yml | 16 +--------------- tools/retry.sh | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) create mode 100755 tools/retry.sh diff --git a/.azure-pipelines/templates/stages/deploy-stage.yml b/.azure-pipelines/templates/stages/deploy-stage.yml index 17cb824d5..ac2044f99 100644 --- a/.azure-pipelines/templates/stages/deploy-stage.yml +++ b/.azure-pipelines/templates/stages/deploy-stage.yml @@ -55,24 +55,10 @@ stages: secureFile: snapcraft.cfg - bash: | set -e - retry_command() { - # based on travis_retry.bash https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_retry.bash - local result=0 - local count=1 - while [[ "${count}" -le 3 ]]; do - result=0 - "${@}" || result="${?}" - if [[ $result -eq 0 ]]; then break; fi - count="$((count + 1))" - sleep 1 - done - - return "${result}" - } mkdir -p .snapcraft ln -s $(snapcraftCfg.secureFilePath) .snapcraft/snapcraft.cfg for SNAP_FILE in snap/*.snap; do - retry_command eval snapcraft upload --release=${{ parameters.snapReleaseChannel }} "${SNAP_FILE}" + tools/retry.sh eval snapcraft upload --release=${{ parameters.snapReleaseChannel }} "${SNAP_FILE}" done displayName: Publish to Snap store - job: publish_docker diff --git a/tools/retry.sh b/tools/retry.sh new file mode 100755 index 000000000..964aab8ea --- /dev/null +++ b/tools/retry.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Retries a command if it fails. +# +# This is based on travis_retry.bash +# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_retry.bash. +set -e +result=0 +count=1 +while [[ "${count}" -le 3 ]]; do + result=0 + "${@}" || result="${?}" + if [[ $result -eq 0 ]]; then break; fi + count="$((count + 1))" + sleep 1 +done + +exit "${result}"