Skip to content

Commit

Permalink
Update to gh-133. Use regex to parse and look for predictable non-ff …
Browse files Browse the repository at this point in the history
…commit error
  • Loading branch information
MadsNielsen committed Aug 15, 2018
1 parent 6166aa8 commit 73cd54f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

/**
* The Git SCM Bridge.
Expand Down Expand Up @@ -85,6 +86,19 @@ public static void pushToBranch(TaskListener listener, GitClient client, String
LOGGER.log(Level.SEVERE, "Failed to push changes to: " + targetRemoteBranch + ".\nException:", ex);
listener.getLogger().println(GitMessages.LOG_PREFIX+ String.format("Failed to push changes to: " + targetRemoteBranch + ".\nException: %s", ex));
throw new PushFailedException(String.format("Failed to push changes to branch, message was:%n%s", ex));
} catch (GitException gex) {
final Pattern nonFastForward = Pattern.compile(".*[rejected].*\\(non-fast-forward\\).*", Pattern.DOTALL);
//Something is wrong on the remote and it's not a fast forward issue...try again
if(gex.getMessage() != null && !nonFastForward.matcher(gex.getMessage()).matches()) {
LOGGER.log(Level.WARNING, LOG_PREFIX + "Failed to push...retying in 5 seconds");
listener.getLogger().println(LOG_PREFIX + "Failed to push...retying in 5 seconds");
try {
Thread.sleep(5000); //Wait 5 seconds
} catch (InterruptedException e) { /* NOOP */ }
GitBridge.pushToBranch(listener, client, sourceLocalBranch, targetRemoteBranch, expandedRepo);
} else {
throw gex;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

import static org.eclipse.jgit.lib.Constants.HEAD;
Expand Down Expand Up @@ -138,17 +140,7 @@ public Revision decorateRevisionToBuild(
gitStrategy.integrateAsGitPluginExt(scm, run, git, listener, marked, triggeredBranch, gitBridge);
//For AccumulatedCommit and in pipeline, immediately push back the merge result
if(gitStrategy instanceof AccumulatedCommitStrategy && run instanceof WorkflowRun) {
try {
GitBridge.pushToBranch(listener, git, expandedIntegrationBranch, triggeredBranch.getName(), repoName);
} catch (GitException fex) {
if(fex.getMessage().contains("error: cannot lock ref")) {
//Something is wrong on the remote...try again
LOGGER.log(Level.WARNING, LOG_PREFIX + "Failed to push...retying in 5 seconds");
listener.getLogger().println(LOG_PREFIX + "Failed to push...retying in 5 seconds");
Thread.sleep(5000);
GitBridge.pushToBranch(listener, git, expandedIntegrationBranch, triggeredBranch.getName(), repoName);
}
}
GitBridge.pushToBranch(listener, git, expandedIntegrationBranch, triggeredBranch.getName(), repoName);
}
run.addAction(new PretestTriggerCommitAction(triggeredBranch, expandedIntegrationBranch, expandedRepo, ucCredentialsId));
} else {
Expand Down

0 comments on commit 73cd54f

Please sign in to comment.