Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job to aggregate can contain variable, expand it before use #72

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -155,13 +189,34 @@ 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();

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);
Expand Down