diff --git a/src/main/java/org/jenkinsci/plugins/pretestedintegration/scm/git/GitBridge.java b/src/main/java/org/jenkinsci/plugins/pretestedintegration/scm/git/GitBridge.java index 187cb0a6..254765dd 100644 --- a/src/main/java/org/jenkinsci/plugins/pretestedintegration/scm/git/GitBridge.java +++ b/src/main/java/org/jenkinsci/plugins/pretestedintegration/scm/git/GitBridge.java @@ -67,7 +67,7 @@ public GitBridge(IntegrationStrategy integrationStrategy, final String integrati public static void pushToIntegrationBranchGit(Run run, TaskListener listener, GitClient client, String expandedRepo, String expandedBranch) throws PushFailedException { try { - pushToBranch(listener, client, expandedBranch, expandedBranch, expandedRepo, 0); + pushToBranch(listener, client, expandedBranch, expandedBranch, expandedRepo); } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Failed to push changes to branch: " + expandedBranch +". Exception:", ex); listener.getLogger().println(GitMessages.LOG_PREFIX + String.format("Failed to push changes to branch: \" + expandedBranch +\". Exception: %s", ex)); @@ -75,27 +75,27 @@ public static void pushToIntegrationBranchGit(Run run, TaskListener listen } } - public static void pushToBranch(TaskListener listener, GitClient client, String sourceLocalBranch, String targetRemoteBranch, String expandedRepo, int retries) throws PushFailedException { + public static void pushToBranch(TaskListener listener, GitClient client, String sourceLocalBranch, String targetRemoteBranch, String expandedRepo) throws PushFailedException { try { LOGGER.log(Level.INFO, "Pushing changes from local branch: " + sourceLocalBranch + " to remote branch: " + targetRemoteBranch); - listener.getLogger().println(GitMessages.LOG_PREFIX + "Pushing changes to branch:"); - client.push(expandedRepo, "refs/heads/" + sourceLocalBranch + ":refs/heads/" + targetRemoteBranch.replace(expandedRepo + "/", "")); + listener.getLogger().println(GitMessages.LOG_PREFIX+ "Pushing changes to branch:"); + client.push(expandedRepo, "refs/heads/" + sourceLocalBranch + ":refs/heads/" + targetRemoteBranch.replace(expandedRepo + "/","")); LOGGER.log(Level.INFO, "Done pushing changes"); - listener.getLogger().println(GitMessages.LOG_PREFIX + "Done pushing changes"); + listener.getLogger().println(GitMessages.LOG_PREFIX+ "Done pushing changes"); } catch (InterruptedException ex) { 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)); + 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() && retries >= 0) { - LOGGER.log(Level.WARNING, LOG_PREFIX + "Failed to push...retrying in 5 seconds"); - listener.getLogger().println(LOG_PREFIX + "Failed to push...retrying in 5 seconds"); + 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, --retries); + GitBridge.pushToBranch(listener, client, sourceLocalBranch, targetRemoteBranch, expandedRepo); } else { throw gex; } @@ -224,7 +224,7 @@ public void pushToIntegrationBranch(AbstractBuild build, BuildListener lis GitSCM gitSCM = findScm(build, listener); GitClient client = gitSCM.createClient(listener, build.getEnvironment(listener), build, build.getWorkspace()); - pushToBranch(listener, client, expandedBranch, expandedBranch, expandedRepo, 0); + pushToBranch(listener, client, expandedBranch, expandedBranch, expandedRepo); } catch (IOException | InterruptedException ex) { LOGGER.log(Level.SEVERE, "Failed to push changes to integration branch. Exception:", ex); listener.getLogger().println(GitMessages.LOG_PREFIX+ String.format("Failed to push changes to integration branch. Exception %s", ex)); diff --git a/src/main/java/org/jenkinsci/plugins/pretestedintegration/scm/git/PretestedIntegrationAsGitPluginExt.java b/src/main/java/org/jenkinsci/plugins/pretestedintegration/scm/git/PretestedIntegrationAsGitPluginExt.java index a59739a5..54fa3a2d 100644 --- a/src/main/java/org/jenkinsci/plugins/pretestedintegration/scm/git/PretestedIntegrationAsGitPluginExt.java +++ b/src/main/java/org/jenkinsci/plugins/pretestedintegration/scm/git/PretestedIntegrationAsGitPluginExt.java @@ -12,29 +12,32 @@ import hudson.plugins.git.extensions.GitSCMExtension; import hudson.plugins.git.extensions.GitSCMExtensionDescriptor; import hudson.plugins.git.util.Build; +import hudson.plugins.git.util.BuildData; import hudson.plugins.git.util.GitUtils; import jenkins.model.Jenkins; -import org.apache.commons.lang.StringUtils; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.URIish; import org.jenkinsci.Symbol; +import org.jenkinsci.plugins.gitclient.ChangelogCommand; import org.jenkinsci.plugins.gitclient.GitClient; import org.jenkinsci.plugins.gitclient.MergeCommand; import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategy; import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategyDescriptor; -import org.jenkinsci.plugins.pretestedintegration.exceptions.EstablishingWorkspaceFailedException; -import org.jenkinsci.plugins.pretestedintegration.exceptions.IntegrationFailedException; -import org.jenkinsci.plugins.pretestedintegration.exceptions.NothingToDoException; -import org.jenkinsci.plugins.pretestedintegration.exceptions.UnsupportedConfigurationException; +import org.jenkinsci.plugins.pretestedintegration.exceptions.*; import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.kohsuke.stapler.DataBoundConstructor; import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; import java.net.URISyntaxException; import java.util.ArrayList; 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; @@ -137,7 +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) { - GitBridge.pushToBranch(listener, git, expandedIntegrationBranch, triggeredBranch.getName(), repoName, 3); + GitBridge.pushToBranch(listener, git, expandedIntegrationBranch, triggeredBranch.getName(), repoName); } run.addAction(new PretestTriggerCommitAction(triggeredBranch, expandedIntegrationBranch, expandedRepo, ucCredentialsId)); } else {