Skip to content
Permalink
Browse files

Merge remote-tracking branch 'upstream/master' into JENKINS-43990

  • Loading branch information
Evaristo Gutiérrez
Evaristo Gutiérrez committed May 2, 2017
2 parents 5c0ca45 + ba659e0 commit ac66b1b6d118784e6e49b06a68c089706808477e
@@ -6,7 +6,7 @@
<version>2.26</version>
</parent>
<artifactId>matrix-project</artifactId>
<version>1.10-SNAPSHOT</version>
<version>1.11-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Matrix Project Plugin</name>
<description>Multi-configuration (matrix) project type.</description>
@@ -94,7 +94,7 @@ private Binding getConfiguredBinding(final MatrixBuildExecution execution) {
for (final ParameterValue pv: parameters) {
if (pv == null) continue;
final String name = pv.getName();
final String value = pv.createVariableResolver(null).resolve(name);
final String value = pv.createVariableResolver(execution.getBuild()).resolve(name);
binding.setVariable(name, value);
}

@@ -25,10 +25,12 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.annotation.Nonnull;

import jenkins.model.RunAction2;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

@@ -48,9 +50,9 @@
* The class itself is public to be visible to core so it can pick up the {@link MatrixChildParametersActionEnvironmentContributor}.
*/
@Restricted(NoExternalUse.class)
public class MatrixChildParametersAction extends ParametersAction implements MatrixChildAction {
public class MatrixChildParametersAction extends ParametersAction implements MatrixChildAction, RunAction2 {

private final List<ParameterValue> parameters;
private transient List<ParameterValue> parameters;

MatrixChildParametersAction(List<ParameterValue> parameters) {
this.parameters = parameters;
@@ -61,6 +63,26 @@
return parameters;
}

@Override
public void onAttached(Run<?, ?> r) {}

@Override
public void onLoad(Run<?, ?> r) {
if (r instanceof MatrixRun) {
MatrixRun run = (MatrixRun) r;
ParametersAction action = run.getParentBuild().getAction(ParametersAction.class);
if (action != null) {
// Parameters of build and its runs are guaranteed to be the same. Even the actual instances are the same
// until it gets (re)loaded from disk when the parameters reside in memory 1+N times squandering memory.
// This populates now volatile collection with parameters shared between the build and all its runs bringing
// the space complexity back to 1.
parameters = action.getParameters();
} else {
parameters = Collections.emptyList();
}
}
}

@Override
public ParameterValue getParameter(String name) {
for (ParameterValue p : parameters) {
@@ -0,0 +1,54 @@
package hudson.matrix;

import hudson.model.*;
import hudson.util.FormValidation;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.*;

/**
* Created by lvotypko on 4/4/17.
*/
public class MatrixChildParametersActionTest {

@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void testLoadingParameters() throws Exception {
MatrixProject project = j.createMatrixProject("project");
StringParameterDefinition def1 = new StringParameterDefinition("definition1", "value1", "description");
StringParameterDefinition def2 = new StringParameterDefinition("definition2", "value2", "description");
ParametersDefinitionProperty prop = new ParametersDefinitionProperty(def1,def2);
project.addProperty(prop);
AxisList axes = new AxisList(
new Axis("a","axis1","axis2"));
project.setAxes(axes);
project.save();
j.buildAndAssertSuccess(project);
MatrixBuild build = project.getLastBuild();
assertEquals("Two configuration should have been build.",2, build.getRuns().size());
checkReferencesForParameters(build);

//reloading
j.jenkins.reload();
project = j.jenkins.getItemByFullName("project", MatrixProject.class);
build = project.getLastBuild();
checkReferencesForParameters(build);
}

private void checkReferencesForParameters(MatrixBuild build) {
ParametersAction action = build.getAction(ParametersAction.class);
ParameterValue definition1 = action.getParameter("definition1");
ParameterValue definition2 = action.getParameter("definition2");
for(MatrixRun run : build.getExactRuns()){
ParametersAction matrichChildParameters = build.getAction(ParametersAction.class);
ParameterValue definition1Child = run.getAction(ParametersAction.class).getParameter("definition1");
ParameterValue definition2Child = run.getAction(ParametersAction.class).getParameter("definition2");
assertSame("Parameters shoud be references to parameters of parent build.", definition1Child, definition1);
assertSame("Parameters shoud be references to parameters of parent build.", definition2Child, definition2);
}
}
}
@@ -97,10 +97,11 @@
@Override public void evaluate() throws Throwable {
Thread.sleep(10000); // If the jobs is loaded too soon, its builds are never loaded.
MatrixProject project = r.j.jenkins.getItemByFullName("p", MatrixProject.class);
AnyOf<Result> isFailedOrAborted = anyOf(equalTo(Result.ABORTED), equalTo(Result.FAILURE));
MatrixBuild p1 = project.getBuildByNumber(1);
MatrixBuild p2 = project.getBuildByNumber(2);

AnyOf<Result> isFailedOrAborted = anyOf(equalTo(Result.ABORTED), equalTo(Result.FAILURE));
assertThat(p1.getResult(), isFailedOrAborted);
MatrixBuild p2 = project.getBuildByNumber(1);
assertThat(p2.getResult(), isFailedOrAborted);

r.j.createOnlineSlave(Label.get("foo"));

0 comments on commit ac66b1b

Please sign in to comment.
You can’t perform that action at this time.