From f7e11a621dec129cbd80bb3aa630c876acfac879 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Fri, 29 Jun 2012 14:21:35 -0700 Subject: [PATCH] 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 --- .../files/slave_scripts/gerrit-git-prep.sh | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/jenkins_slave/files/slave_scripts/gerrit-git-prep.sh b/modules/jenkins_slave/files/slave_scripts/gerrit-git-prep.sh index 91f35e29ef..5535fdfdfc 100755 --- a/modules/jenkins_slave/files/slave_scripts/gerrit-git-prep.sh +++ b/modules/jenkins_slave/files/slave_scripts/gerrit-git-prep.sh @@ -38,12 +38,32 @@ fi function merge_change { PROJECT=$1 REFSPEC=$2 - - git fetch https://$SITE/p/$PROJECT $REFSPEC - # This should be equivalent to what gerrit does if a repo is - # set to "merge commits when necessary" and "automatically resolve - # conflicts" is set to true: - git merge -s resolve FETCH_HEAD + MAX_ATTEMPTS=${3:-3} + COUNT=0 + + 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 + # set to "merge commits when necessary" and "automatically resolve + # conflicts" is set to true: + 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 {