Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retries option #43

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions posix/clone
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,31 @@ case $DRONE_COMMIT_REF in
refs/merge-requests/* ) CLONE_TYPE=pull_request ;;
esac

git_clone_retry(){
retries="${PLUGIN_RETRIES:-0}"
if [ -n "${retries##*[0-9]*}" ] || [ "${retries}" -lt 0 ]; then
echo "PLUGIN_RETRIES defined but is not a number: ${retries}" >&2
exit 1
fi

echo "Cloning with ${retries} retries"
n=0
until [ "$n" -gt "${retries}" ]; do
$1 && return
n=$((n+1))
done

exit 1
}

case $CLONE_TYPE in
pull_request)
clone-pull-request
git_clone_retry clone-pull-request
;;
tag)
clone-tag
git_clone_retry clone-tag
;;
*)
clone-commit
git_clone_retry clone-commit
;;
esac
esac