move retry to script

This commit is contained in:
Brad Warren 2020-09-28 14:54:55 -07:00
parent e066766cc9
commit 4275d61b55
2 changed files with 18 additions and 15 deletions

View file

@ -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

17
tools/retry.sh Executable file
View file

@ -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}"