diff --git a/src/main/java/hudson/plugins/git/GitSCM.java b/src/main/java/hudson/plugins/git/GitSCM.java index a26f51363b..c1c3387ffe 100644 --- a/src/main/java/hudson/plugins/git/GitSCM.java +++ b/src/main/java/hudson/plugins/git/GitSCM.java @@ -97,6 +97,7 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.concurrent.TimeUnit; import static hudson.init.InitMilestone.JOB_LOADED; import static hudson.init.InitMilestone.PLUGINS_STARTED; @@ -1302,7 +1303,27 @@ public void checkout(Run build, Launcher launcher, FilePath workspace, Tas ext.beforeCheckout(this, build, git, listener); } - retrieveChanges(build, git, listener); + boolean retrievedChanges = false; + + for (int tryCount = 1; tryCount <= 5; tryCount++) { + try { + retrieveChanges(build, git, listener); + retrievedChanges = true; + break; + } catch (AbortException ex) { + int waitTime = tryCount * 10; + listener.getLogger().println("Failed to retrieve Git changes with an error. Will make another attempt after " + waitTime + " seconds."); + TimeUnit.SECONDS.sleep(waitTime); + } + } + + if (!retrievedChanges) + { + String errorMessage = "Got a fatal error while retrieving Git changes. Reached maximum retry limit, won't try again."; + listener.getLogger().println(errorMessage); + throw new AbortException(errorMessage); + } + Build revToBuild = determineRevisionToBuild(build, buildData, environment, git, listener); // Track whether we're trying to add a duplicate BuildData, now that it's been updated with