Make git fetching in gerrit-git-prep more robust.
gerrit-git-prep would fail if a single git fetch was unable to get what it requested from Gerrit. These errors occur due to server side issues and gerrit-git-prep should simply try again. This patch has gerrit-git-prep attempt each git fetch at least three times with a random sleep interval between 30 and 90 seconds between each fetch. Change-Id: Ib7f9292ec6e55ee7e6d3a5fe832c302660a1aa00
This commit is contained in:
parent
b9f7630c24
commit
f7e11a621d
@ -38,12 +38,32 @@ fi
|
|||||||
function merge_change {
|
function merge_change {
|
||||||
PROJECT=$1
|
PROJECT=$1
|
||||||
REFSPEC=$2
|
REFSPEC=$2
|
||||||
|
MAX_ATTEMPTS=${3:-3}
|
||||||
|
COUNT=0
|
||||||
|
|
||||||
git fetch https://$SITE/p/$PROJECT $REFSPEC
|
until git fetch https://$SITE/p/$PROJECT $REFSPEC
|
||||||
|
do
|
||||||
|
COUNT=$(($COUNT + 1))
|
||||||
|
if [ $COUNT -eq $MAX_ATTEMPTS ]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
SLEEP_TIME=$((30 + $RANDOM % 60))
|
||||||
|
sleep $SLEEP_TIME
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $COUNT -lt $MAX_ATTEMPTS ]
|
||||||
|
then
|
||||||
# This should be equivalent to what gerrit does if a repo is
|
# This should be equivalent to what gerrit does if a repo is
|
||||||
# set to "merge commits when necessary" and "automatically resolve
|
# set to "merge commits when necessary" and "automatically resolve
|
||||||
# conflicts" is set to true:
|
# conflicts" is set to true:
|
||||||
git merge -s resolve FETCH_HEAD
|
git merge -s resolve FETCH_HEAD
|
||||||
|
else
|
||||||
|
# Failed to fetch too many times. Notify jenkins of the failure.
|
||||||
|
# This is necessary because set -e does not apply to the condition of
|
||||||
|
# until.
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function merge_changes {
|
function merge_changes {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user