diff --git a/src/main/java/hudson/tasks/test/AggregatedTestResultPublisher.java b/src/main/java/hudson/tasks/test/AggregatedTestResultPublisher.java index afe775d2c..904f1a98d 100644 --- a/src/main/java/hudson/tasks/test/AggregatedTestResultPublisher.java +++ b/src/main/java/hudson/tasks/test/AggregatedTestResultPublisher.java @@ -27,6 +27,7 @@ import hudson.model.AbstractBuild; import hudson.model.AbstractProject; import hudson.model.AutoCompletionCandidates; +import hudson.EnvVars; import hudson.Extension; import hudson.Launcher; import hudson.Util; @@ -95,9 +96,20 @@ public AggregatedTestResultPublisher(String jobs, boolean includeFailedBuilds) { public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { // add a TestResult just so that it can show up later. - build.addAction(new TestResultAction(jobs, includeFailedBuilds, build)); + // Expand the jobs String as it can contain variable + String expandedJobs = this.getJobs(build.getEnvironment(listener)); + build.addAction(new TestResultAction(expandedJobs, includeFailedBuilds, build)); return true; } + + /** + * Return the expanded job list + * @param env + * @return + */ + public String getJobs(EnvVars env) { + return (env != null ? env.expand(this.jobs) : this.jobs); + } public BuildStepMonitor getRequiredMonitorService() { return BuildStepMonitor.NONE; diff --git a/src/test/java/hudson/tasks/test/AggregatedTestResultPublisherTest.java b/src/test/java/hudson/tasks/test/AggregatedTestResultPublisherTest.java index 2b871ae9c..05390c09c 100644 --- a/src/test/java/hudson/tasks/test/AggregatedTestResultPublisherTest.java +++ b/src/test/java/hudson/tasks/test/AggregatedTestResultPublisherTest.java @@ -1,11 +1,14 @@ package hudson.tasks.test; import com.google.common.collect.ImmutableList; + import hudson.Functions; import hudson.model.AbstractBuild; import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; +import hudson.model.ParametersDefinitionProperty; import hudson.model.Result; +import hudson.model.StringParameterDefinition; import hudson.tasks.BatchFile; import hudson.tasks.BuildTrigger; import hudson.tasks.Fingerprinter; @@ -26,6 +29,8 @@ import static org.junit.Assert.assertThat; public class AggregatedTestResultPublisherTest { + private static final String VAR = "var"; + private static final String JOBS = "$" + VAR; public static final String TEST_PROJECT_NAME = "junit"; public static final String AGGREGATION_PROJECT_NAME = "aggregated"; @Rule @@ -125,6 +130,35 @@ public void testResultsAndAggregatedTestResults() throws Exception { .follow() .hasLinkToTestResultOfBuild(TEST_PROJECT_NAME, 1); } + + + @LocalData + @Test + public void testResultsAndAggregatedTestResultsParam() throws Exception { + createUpstreamParamProjectWithTests(); + createDownstreamParamProjectWithTests(); + + buildAndSetupPageObjects(); + + projectPage.getLatestTestReportLink() + .assertHasLatestTestResultText() + .assertHasTests() + .follow(); + projectPage.getLatestAggregatedTestReportLink() + .assertHasLatestAggregatedTestResultText() + .assertHasTests() + .follow(); + + buildPage.getTestReportLink() + .assertHasTestResultText() + .assertHasTests() + .follow(); + buildPage.getAggregatedTestReportLink() + .assertHasAggregatedTestResultText() + .assertHasTests() + .follow() + .hasLinkToTestResultOfBuild(TEST_PROJECT_NAME, 1); + } private void buildAndSetupPageObjects() throws Exception { buildOnce(); @@ -155,6 +189,15 @@ private void createUpstreamProjectWithNoTests() throws Exception { addFingerprinterToProject(upstreamProject, singleContents, singleFiles); upstreamProject.setQuietPeriod(0); } + + private void createUpstreamParamProjectWithTests() throws Exception { + upstreamProject = j.createFreeStyleProject(AGGREGATION_PROJECT_NAME); + StringParameterDefinition params = new StringParameterDefinition(VAR, TEST_PROJECT_NAME); + upstreamProject.addProperty(new ParametersDefinitionProperty(params)); + addFingerprinterToProject(upstreamProject, singleContents, singleFiles); + upstreamProject.setQuietPeriod(0); + addJUnitResultArchiver(upstreamProject); + } private void createDownstreamProjectWithTests() throws Exception { createDownstreamProjectWithNoTests(); @@ -162,6 +205,18 @@ private void createDownstreamProjectWithTests() throws Exception { addJUnitResultArchiver(downstreamProject); j.jenkins.rebuildDependencyGraph(); } + + private void createDownstreamParamProjectWithTests() throws Exception { + downstreamProject = j.createFreeStyleProject(TEST_PROJECT_NAME); + downstreamProject.setQuietPeriod(0); + addFingerprinterToProject(downstreamProject, singleContents, singleFiles); + upstreamProject.getPublishersList().add(new BuildTrigger(ImmutableList.of(downstreamProject), Result.SUCCESS)); + upstreamProject.getPublishersList().add(new AggregatedTestResultPublisher(JOBS)); + + addJUnitResultArchiver(downstreamProject); + + j.jenkins.rebuildDependencyGraph(); + } private void createDownstreamProjectWithNoTests() throws Exception { downstreamProject = j.createFreeStyleProject(TEST_PROJECT_NAME);