Skip to content

Commit

Permalink
[JENKINS-30885] Added variable expansion to rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Lacour committed Oct 12, 2015
1 parent 13df72c commit f3a2cac
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Expand Up @@ -107,6 +107,7 @@ public BuildWrapper.Environment setUp(AbstractBuild build, Launcher launcher, Bu
} catch (Exception ex) {
build.setResult(Result.FAILURE);
listener.getLogger().println(String.format("%sUnexpected error. Check log for details", LOG_PREFIX));
ex.printStackTrace(listener.getLogger());
logger.log(Level.SEVERE, LOG_PREFIX + "- setUp() - Unexpected error", ex);
proceedToBuildStep = false;
}
Expand Down
Expand Up @@ -235,8 +235,6 @@ public int git(AbstractBuild<?, ?> build, Launcher launcher, BuildListener liste
public void ensureBranch(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, String branch) throws EstablishWorkspaceException {
logger.entering("GitBridge", "ensureBranch", new Object[] { build, branch, listener, launcher });// Generated code DONT TOUCH! Bookmark: eb203ba8b33b4c38087310c398984c1a

listener.getLogger().println(String.format(LOG_PREFIX + "Checking out integration branch %s:", getBranch()));

try {
EnvVars environment = build.getEnvironment(listener);
listener.getLogger().println(String.format(LOG_PREFIX + "Checking out integration branch %s:", getExpandedBranch(environment)));
Expand Down Expand Up @@ -561,7 +559,7 @@ private boolean validateMultiScm(List<SCM> scms) throws UnsupportedConfiguration
public int countCommits(AbstractBuild<?, ?> build, BuildListener listener) throws IOException, InterruptedException {
ObjectId commitId = getCommitId(build, listener);
GitClient client = Git.with(listener, build.getEnvironment(listener)).in(resolveWorkspace(build, listener)).getClient();
GetCommitCountFromBranchCallback commitCountCallback = new GetCommitCountFromBranchCallback(listener, commitId, getBranch());
GetCommitCountFromBranchCallback commitCountCallback = new GetCommitCountFromBranchCallback(listener, commitId, getExpandedBranch(build.getEnvironment(listener)));
int commitCount = client.withRepository(commitCountCallback);
return commitCount;
}
Expand Down
Expand Up @@ -256,15 +256,16 @@ private boolean tryRebase(AbstractBuild<?, ?> build, Launcher launcher, BuildLis
logger.log(Level.INFO, String.format(LOG_PREFIX + "Attempting rebase."));
GitClient client = Git.with(listener, build.getEnvironment(listener)).in(bridge.resolveWorkspace(build, listener)).getClient();
ObjectId commitId = bridge.getCommitId(build, listener);
String expandedBranch = bridge.getExpandedBranch(build.getEnvironment(listener));

//Rebase the commit, then checkout master for a fast-forward merge.
int rebaseCode = bridge.git(build, launcher, listener, "rebase", bridge.getBranch(), commitId.getName());
int rebaseCode = bridge.git(build, launcher, listener, "rebase", expandedBranch, commitId.getName());
if (rebaseCode != 0) {
throw new IntegationFailedExeception("Rebase failed with exit code " + rebaseCode);
}
ObjectId rebasedCommit = client.revParse("HEAD");
logger.log(Level.INFO, String.format(LOG_PREFIX + "Rebase successful. Attempting fast-forward merge."));
client.checkout().ref(bridge.getBranch()).execute();
client.checkout().ref(expandedBranch).execute();
client.merge().setRevisionToMerge(rebasedCommit).execute();
logger.log(Level.INFO, String.format(LOG_PREFIX + "Fast-forward merge successful. Exiting tryRebase."));
return true;
Expand Down
Expand Up @@ -6,7 +6,6 @@
import hudson.model.FreeStyleProject;
import hudson.model.Job;
import hudson.model.TaskListener;
import hudson.model.queue.QueueTaskFuture;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
Expand Down Expand Up @@ -61,8 +60,10 @@ public void testEnvironmentVariables() throws Exception {
CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
project.getBuildersList().add(builder);

QueueTaskFuture<FreeStyleBuild> build = project.scheduleBuild2(0);
FreeStyleBuild build = project.scheduleBuild2(0).get();
jenkins.waitUntilNoActivityUpTo(60000);
String console = jenkins.createWebClient().getPage(build, "console").asText();
System.out.println(console);
jenkins.assertBuildStatusSuccess(build);
System.out.println("Built with branch '" + INTEGRATION_BRANCH + "' on repository '" + REPOSITORY + "'.");
assert builder.getEnvVars().get("INTEGRATION_BRANCH", "default").equals(INTEGRATION_BRANCH);
Expand Down

0 comments on commit f3a2cac

Please sign in to comment.