Skip to content
Browse files

[FIXED JENKINS-9729] account for matrix parent triggering each config…

…uration,

to make TriggeredBuildSelector support copying to/from matrix projects.
  • Loading branch information...
1 parent 33a6574 commit b9b151718fa30e3ba5370dbb5ab2a9f0241718b5 @alanharder alanharder committed
View
10 src/main/java/hudson/plugins/copyartifact/TriggeredBuildSelector.java
@@ -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;
@@ -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());
View
47 src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
@@ -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));
@@ -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);

0 comments on commit b9b1517

Please sign in to comment.
Something went wrong with that request. Please try again.