Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #540 from cjo9900/JENKINS-7162
[FIXED JENKINS-7162] Add missing parameters as defaults when called from...
  • Loading branch information
vjuranek committed Aug 15, 2012
2 parents c14c761 + 7e0d7c0 commit 0ddceed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
21 changes: 15 additions & 6 deletions core/src/main/java/hudson/cli/BuildCommand.java
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
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

0 comments on commit 0ddceed

Please sign in to comment.