Skip to content

Commit

Permalink
[FIXED JENKINS-25624] Support CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedam committed Aug 27, 2016
1 parent 7bc4258 commit e5b77a9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Expand Up @@ -24,6 +24,7 @@
package hudson.plugins.matrix_configuration_parameter;

import hudson.Extension;
import hudson.cli.CLICommand;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterValue;
import hudson.model.Result;
Expand All @@ -32,6 +33,7 @@
import hudson.plugins.matrix_configuration_parameter.shortcut.ResultShortcut;
import net.sf.json.JSONObject;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -129,8 +131,29 @@ public ParameterValue createValue(StaplerRequest req) {
}
}

/**
* {@inheritDoc}
*/
@Override
public ParameterValue createValue(CLICommand command, String value) throws IOException, InterruptedException {
return createValue(value);
}


/**
* Decide combinations from combinations filter
*
* @param value groovy expression for combinations filter
* @return matrix-combinations parameter with the specified combinations filter
*
* @since 1.1.0
*/
protected ParameterValue createValue(String value) throws IOException, InterruptedException {
return new DefaultMatrixCombinationsParameterValue(
getName(),
getDescription(),
value
);
}

@Override
public MatrixCombinationsParameterValue getDefaultParameterValue() {
Expand Down
Expand Up @@ -25,6 +25,8 @@
package hudson.plugins.matrix_configuration_parameter;

import static org.junit.Assert.*;

import hudson.cli.CLI;
import hudson.matrix.AxisList;
import hudson.matrix.Combination;
import hudson.matrix.MatrixBuild;
Expand Down Expand Up @@ -557,4 +559,34 @@ public void testMultiParameters() throws Exception {
j.assertCombinationChecked(page, 1, true, axes, "value2");
j.assertCombinationChecked(page, 1, false, axes, "value3");
}

@Test
public void testCliBuild() throws Exception {
AxisList axes = new AxisList(new TextAxis("axis1", "value1", "value2", "value3"));
MatrixProject p = j.createMatrixProject();
p.setAxes(axes);
p.addProperty(new ParametersDefinitionProperty(
new MatrixCombinationsParameterDefinition("combinations", "", "")
));

CLI cli = new CLI(j.getURL());
int ret = cli.execute(
"build",
p.getFullName(),
"-p",
// You can't use axis1 != 'value2'
// for JENKINS-21160 (fixed in Jenkins 1.606)
"combinations=axis1 in ['value1', 'value3']"
);
assertEquals(0, ret);

j.waitUntilNoActivity();

MatrixBuild b = p.getLastBuild();
j.assertBuildStatusSuccess(b);

assertNotNull(b.getExactRun(new Combination(axes, "value1")));
assertNull(b.getExactRun(new Combination(axes, "value2")));
assertNotNull(b.getExactRun(new Combination(axes, "value3")));
}
}

0 comments on commit e5b77a9

Please sign in to comment.