Skip to content

Commit

Permalink
[FIXED JENKINS-9729] account for matrix parent triggering each config…
Browse files Browse the repository at this point in the history
…uration,

to make TriggeredBuildSelector support copying to/from matrix projects.
  • Loading branch information
alanharder committed Jul 23, 2011
1 parent 33a6574 commit b9b1517
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
Expand Up @@ -25,6 +25,8 @@

import hudson.EnvVars;
import hudson.Extension;
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixRun;
import hudson.model.Descriptor;
import hudson.model.Cause;
import hudson.model.Cause.UpstreamCause;
Expand All @@ -50,8 +52,12 @@ public boolean isFallbackToLastSuccessful() {

@Override
public Run<?,?> getBuild(Job<?,?> job, EnvVars env, BuildFilter filter, Run<?,?> parent) {
String jobName = job.getFullName();
for (Cause cause : parent.getCauses()) {
// Upstream job for matrix will be parent project, not individual configuration:
String jobName = job instanceof MatrixConfiguration
? job.getParent().getFullName() : job.getFullName();
// Matrix run is triggered by its parent project, so check causes of parent build:
for (Cause cause : parent instanceof MatrixRun
? ((MatrixRun)parent).getParentBuild().getCauses() : parent.getCauses()) {
if (cause instanceof UpstreamCause
&& jobName.equals(((UpstreamCause)cause).getUpstreamProject())) {
Run<?,?> run = job.getBuildByNumber(((UpstreamCause)cause).getUpstreamBuild());
Expand Down
47 changes: 46 additions & 1 deletion src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
Expand Up @@ -487,7 +487,7 @@ public void testPermalinkBuildSelector() throws Exception {

public void testTriggeredBuildSelector() throws Exception {
FreeStyleProject other = createArtifactProject(),
p = createFreeStyleProject();
p = createFreeStyleProject();
p.getBuildersList().add(new CopyArtifact(other.getName(),
new TriggeredBuildSelector(false), "*.txt", "", false, false));
other.getPublishersList().add(new BuildTrigger(p.getFullName(), false));
Expand All @@ -510,6 +510,51 @@ public void testTriggeredBuildSelector() throws Exception {
assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, new UserCause()).get());
}

/**
* When copying from a particular matrix configuration, the upstream project
* is the matrix parent.
*/
public void testTriggeredBuildSelectorFromMatrix() throws Exception {
MatrixProject other = createMatrixArtifactProject();
FreeStyleProject p = createFreeStyleProject();
p.getBuildersList().add(new CopyArtifact(other.getName() + "/FOO=two",
new TriggeredBuildSelector(false), "*.txt", "", false, false));
other.getPublishersList().add(new BuildTrigger(p.getFullName(), false));
hudson.rebuildDependencyGraph();
assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
// p#1 was triggered, now building.
FreeStyleBuild b = p.getBuildByNumber(1);
for (int i = 0; b == null && i < 1000; i++) { Thread.sleep(10); b = p.getBuildByNumber(1); }
assertNotNull(b);
while (b.isBuilding()) Thread.sleep(10);
assertBuildStatusSuccess(b);
assertFile(true, "foo.txt", b);
assertFile(true, "two.txt", b);
}

/**
* When copying to a matrix job, need to check the upstream cause of the
* matrix parent.
*/
public void testTriggeredBuildSelectorToMatrix() throws Exception {
FreeStyleProject other = createArtifactProject();
MatrixProject p = createMatrixProject();
p.setAxes(new AxisList(new Axis("FOO", "one", "two")));
p.getBuildersList().add(new CopyArtifact(other.getName(),
new TriggeredBuildSelector(false), "*.txt", "", false, false));
other.getPublishersList().add(new BuildTrigger(p.getFullName(), false));
hudson.rebuildDependencyGraph();
assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
// p#1 was triggered, now building.
MatrixBuild b = p.getBuildByNumber(1);
for (int i = 0; b == null && i < 1000; i++) { Thread.sleep(10); b = p.getBuildByNumber(1); }
assertNotNull(b);
while (b.isBuilding()) Thread.sleep(10);
assertBuildStatusSuccess(b);
MatrixRun r = b.getRuns().get(0);
assertFile(true, "foo.txt", r);
}

public void testFlatten() throws Exception {
FreeStyleProject other = createArtifactProject(),
p = createProject(other.getName(), "", "newdir", false, true, false);
Expand Down

0 comments on commit b9b1517

Please sign in to comment.