}
public void testMatrixBuildsOnSameNodes() throws Exception {
// all builds runs on master.
// upstream matrix projects creates properties files in each builds.
MatrixProject upstream = createMatrixProject();
upstream.setAxes(new AxisList(new TextAxis("childname", "child1", "child2")));
WriteFileBuilder wfb = new WriteFileBuilder("properties.txt", "triggered_${childname}=true");
FreeStyleProject downstream = createFreeStyleProject();
// Without useMatrixBuild, publisher
// Downstream project is triggered without parameters.
{
upstream.getBuildersList().clear();
upstream.getBuildersList().add(wfb);
upstream.getPublishersList().clear();
upstream.getPublishersList().add(new BuildTrigger(
new BuildTriggerConfig(downstream.getFullName(), ResultCondition.SUCCESS, true, Arrays.<AbstractBuildParameters>asList(
new FileBuildParameters("properties.txt", null, false, false, null, false)
))
));
jenkins.rebuildDependencyGraph();
assertEquals(0, downstream.getBuilds().size());
upstream.scheduleBuild2(0).get();
waitUntilNoActivity();
assertEquals(1, downstream.getBuilds().size());
FreeStyleBuild build = downstream.getLastBuild();
assertNull(getStringParameterValue(build, "triggered_child1"));
assertNull(getStringParameterValue(build, "triggered_child2"));
build.delete();
}
// With useMatrixBuild, publisher
// Downstream project is triggered with parameters, merging properties files in all children.
{
upstream.getBuildersList().clear();
upstream.getBuildersList().add(wfb);
upstream.getPublishersList().clear();
upstream.getPublishersList().add(new BuildTrigger(
new BuildTriggerConfig(downstream.getFullName(), ResultCondition.SUCCESS, true, Arrays.<AbstractBuildParameters>asList(
new FileBuildParameters("properties.txt", null, false, true, null, false)
))
));
jenkins.rebuildDependencyGraph();
assertEquals(0, downstream.getBuilds().size());
upstream.scheduleBuild2(0).get();
waitUntilNoActivity();
// Build is triggered without parameters.
assertEquals(1, downstream.getBuilds().size());
FreeStyleBuild build = downstream.getLastBuild();
assertEquals("true", getStringParameterValue(build, "triggered_child1"));
assertEquals("true", getStringParameterValue(build, "triggered_child2"));
build.delete();
}
// Without useMatrixBuild, builder
// Downstream project is triggered with parameters of each child.
{
upstream.getBuildersList().clear();
upstream.getBuildersList().add(wfb);
upstream.getBuildersList().add(new TriggerBuilder(
new BlockableBuildTriggerConfig(downstream.getFullName(), null, Arrays.<AbstractBuildParameters>asList(
new FileBuildParameters("properties.txt", null, false, false, null, false)
))
));
upstream.getPublishersList().clear();
jenkins.rebuildDependencyGraph();
assertEquals(0, downstream.getBuilds().size());
upstream.scheduleBuild2(0).get();
waitUntilNoActivity();
// Build is triggered in each builds with parameters.
assertEquals(2, downstream.getBuilds().size());
FreeStyleBuild build1 = downstream.getLastBuild();
FreeStyleBuild build2 = build1.getPreviousBuild();
if (build1.getCause(Cause.UpstreamCause.class).getUpstreamProject().contains("child1")) {
assertEquals("true", getStringParameterValue(build1, "triggered_child1"));
assertNull(getStringParameterValue(build1, "triggered_child2"));
assertNull(getStringParameterValue(build2, "triggered_child1"));
assertEquals("true", getStringParameterValue(build2, "triggered_child2"));
} else {
assertEquals("true", getStringParameterValue(build2, "triggered_child1"));
assertNull(getStringParameterValue(build2, "triggered_child2"));
assertNull(getStringParameterValue(build1, "triggered_child1"));
assertEquals("true", getStringParameterValue(build1, "triggered_child2"));
}
build2.delete();
build1.delete();
}
// With useMatrixBuild, publisher
// Downstream project is triggered with parameters of each child.
// (useMatrixBuild is ignored)
{
upstream.getBuildersList().clear();
upstream.getBuildersList().add(wfb);
upstream.getBuildersList().add(new TriggerBuilder(
new BlockableBuildTriggerConfig(downstream.getFullName(), null, Arrays.<AbstractBuildParameters>asList(
new FileBuildParameters("properties.txt", null, false, true, null, false)
))
));
upstream.getPublishersList().clear();
jenkins.rebuildDependencyGraph();
assertEquals(0, downstream.getBuilds().size());
upstream.scheduleBuild2(0).get();
waitUntilNoActivity();
// Build is triggered in each builds with parameters.
assertEquals(2, downstream.getBuilds().size());
FreeStyleBuild build1 = downstream.getLastBuild();