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

[FIXED JENKINS-7162] Add missing parameters as defaults when called from... #540

Merged
merged 1 commit into from
Aug 15, 2012
Merged
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
21 changes: 15 additions & 6 deletions core/src/main/java/hudson/cli/BuildCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected int run() throws Exception {
if (pdp==null)
throw new AbortException(job.getFullDisplayName()+" is not parameterized but the -p option was specified");

List<ParameterValue> values = new ArrayList<ParameterValue>();
List<ParameterValue> values = new ArrayList<ParameterValue>();

for (Entry<String, String> e : parameters.entrySet()) {
String name = e.getKey();
Expand All @@ -101,7 +101,16 @@ protected int run() throws Exception {
name, EditDistance.findNearest(name, pdp.getParameterDefinitionNames())));
values.add(pd.createValue(this,e.getValue()));
}


// handle missing parameters by adding as default values ISSUE JENKINS-7162
for(ParameterDefinition pd : pdp.getParameterDefinitions()) {
if (parameters.containsKey(pd.getName()))
continue;

// not passed in use default
values.add(pd.getDefaultParameterValue());
}

a = new ParametersAction(values);
}

Expand Down Expand Up @@ -145,17 +154,17 @@ protected void printUsageSummary(PrintStream stderr) {
}

public static class CLICause extends UserIdCause {

private String startedBy;

public CLICause(){
startedBy = "unknown";
}

public CLICause(String startedBy){
this.startedBy = startedBy;
}

@Override
public String getShortDescription() {
return Messages.BuildCommand_CLICause_ShortDescription(startedBy);
Expand Down
15 changes: 15 additions & 0 deletions test/src/test/groovy/hudson/cli/BuildCommandTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ public class BuildCommandTest extends HudsonTestCase {
}
}

void testDefaultParameters() {
def p = createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty([new StringParameterDefinition("key","default"), new StringParameterDefinition("key2","default2") ]));

def cli = new CLI(getURL())
try {
cli.execute(["build","-s","-p","key=foobar",p.name])
def b = assertBuildStatusSuccess(p.getBuildByNumber(1))
assertEquals("foobar",b.getAction(ParametersAction.class).getParameter("key").value)
assertEquals("default2",b.getAction(ParametersAction.class).getParameter("key2").value)
} finally {
cli.close();
}
}

void testConsoleOutput() {
def p = createFreeStyleProject()
def cli = new CLI(getURL())
Expand Down