Permalink
Browse files

Created a unit test that reproduces JENKINS-23179

  • Loading branch information...
galbramc authored and MarkEWaite committed Jun 9, 2014
1 parent f214868 commit cecfd4f509ce2f678bf6ad844aa059b50d17e5eb
@@ -3,6 +3,8 @@
import com.google.common.collect.Lists;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.model.*;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.CleanBeforeCheckout;
@@ -187,6 +189,19 @@ protected FreeStyleBuild build(final FreeStyleProject project, final String pare
}
return build;
}

protected MatrixBuild build(final MatrixProject project, final Result expectedResult, final String...expectedNewlyCommittedFiles) throws Exception {
final MatrixBuild build = project.scheduleBuild2(0, new Cause.UserCause()).get();
System.out.println(build.getLog());
for(final String expectedNewlyCommittedFile : expectedNewlyCommittedFiles) {
assertTrue(expectedNewlyCommittedFile + " file not found in workspace", build.getWorkspace().child(expectedNewlyCommittedFile).exists());
}
if(expectedResult != null) {
assertBuildStatus(expectedResult, build);
}
return build;
}


protected EnvVars getEnvVars(FreeStyleProject project) {
for (hudson.tasks.Builder b : project.getBuilders()) {
@@ -1,8 +1,13 @@
package hudson.plugins.git;

import com.google.common.collect.Lists;

import hudson.EnvVars;
import hudson.FilePath;
import hudson.matrix.Axis;
import hudson.matrix.AxisList;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.model.*;
import hudson.plugins.git.GitSCM.BuildChooserContextImpl;
import hudson.plugins.git.browser.GitRepositoryBrowser;
@@ -985,6 +990,51 @@ public void testMergeFailedWithSlave() throws Exception {
assertFalse("scm polling should not detect any more changes after build", project.poll(listener).hasChanges());
}


public void testMergeWithMatrixBuild() throws Exception {

MatrixProject project = createMatrixProject("xyz");
project.setAxes(new AxisList(new Axis("VAR","a","b")));

//FreeStyleProject project = setupSimpleProject("master");
//project.setAssignedLabel(createSlave().getSelfLabel());

GitSCM scm = new GitSCM(
createRemoteRepositories(),
Collections.singletonList(new BranchSpec("*")),
false, Collections.<SubmoduleConfig>emptyList(),
null, null,
Collections.<GitSCMExtension>emptyList());
scm.getExtensions().add(new PreBuildMerge(new UserMergeOptions("origin", "integration", null)));
project.setScm(scm);

// create initial commit and then run the build against it:
commit("commitFileBase", johnDoe, "Initial Commit");
testRepo.git.branch("integration");
build(project, Result.SUCCESS, "commitFileBase");


testRepo.git.checkout(null, "topic1");
final String commitFile1 = "commitFile1";
commit(commitFile1, johnDoe, "Commit number 1");
final MatrixBuild build1 = build(project, Result.SUCCESS, commitFile1);
assertTrue(build1.getWorkspace().child(commitFile1).exists());

assertFalse("scm polling should not detect any more changes after build", project.poll(listener).hasChanges());
// do what the GitPublisher would do
testRepo.git.deleteBranch("integration");
testRepo.git.checkout("topic1", "integration");

testRepo.git.checkout("master", "topic2");
final String commitFile2 = "commitFile2";
commit(commitFile2, johnDoe, "Commit number 2");
assertTrue("scm polling did not detect commit2 change", project.poll(listener).hasChanges());
final MatrixBuild build2 = build(project, Result.SUCCESS, commitFile2);
assertTrue(build2.getWorkspace().child(commitFile2).exists());
assertBuildStatusSuccess(build2);
assertFalse("scm polling should not detect any more changes after build", project.poll(listener).hasChanges());
}

public void testEnvironmentVariableExpansion() throws Exception {
FreeStyleProject project = createFreeStyleProject();
project.setScm(new GitSCM("${CAT}"+testRepo.gitDir.getPath()));

0 comments on commit cecfd4f

Please sign in to comment.