Skip to content

Commit

Permalink
[FIXED JENKINS-22923] - Allow the specification of tool version from CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
  • Loading branch information
oleg-nenashev committed May 9, 2014
1 parent 87ecad8 commit da07afb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Expand Up @@ -20,11 +20,13 @@
import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterValue;
import com.synopsys.arc.jenkinsci.plugins.customtools.Messages;
import hudson.Extension;
import hudson.cli.CLICommand;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterDefinition.ParameterDescriptor;
import hudson.model.ParameterValue;
import hudson.model.StringParameterValue;
import hudson.tools.ToolInstallation;
import java.io.IOException;
import javax.annotation.CheckForNull;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -75,28 +77,32 @@ private ExtendedChoiceParameterDefinition getVersionsListSource() {
if (versionConfig == null) {
throw new IllegalStateException(
Messages.Versions_ToolVersionParameterDefinition_GetVersionConfigError(toolName));
}
return versionConfig.getVersionsListSource();
}

return versionConfig.getVersionsListSource();
}

@Override
public StringParameterValue createValue(StaplerRequest req, JSONObject jo)
throws IllegalStateException
{
throws IllegalStateException {
ExtendedChoiceParameterValue paramVal = (ExtendedChoiceParameterValue)
getVersionsListSource().createValue(req, jo);
return new StringParameterValue(paramVal.getName(), paramVal.value);
}

@Override
public StringParameterValue createValue(StaplerRequest req) {

public StringParameterValue createValue(StaplerRequest req) {
ExtendedChoiceParameterValue paramVal = (ExtendedChoiceParameterValue)
getVersionsListSource().createValue(req);
return new StringParameterValue(paramVal.getName(), paramVal.value);
}

@Override
public ParameterValue createValue(CLICommand command, String value) throws IOException, InterruptedException {
ParameterValue val = getDefaultParameterValue();
return new StringParameterValue(val.getName(), value);
}

@Override
public ParameterValue getDefaultParameterValue() {
ExtendedChoiceParameterValue paramVal = (ExtendedChoiceParameterValue)
Expand Down
Expand Up @@ -79,7 +79,6 @@ private FreeStyleProject setupJobWithVersionParam(Slave targetSlave) throws Exce
new ToolVersionParameterDefinition(TEST_TOOL_NAME));

project.addProperty(pdp);
project.getBuildersList().add(new CaptureEnvironmentBuilder());
project.setAssignedNode(targetSlave);

return project;
Expand Down Expand Up @@ -109,4 +108,27 @@ public void testDefaultValueOnCLICall() throws Exception {
Assert.assertTrue("Executor is dead: "+exec, exec.isAlive());
}
}

@Test
@Bug(22923)
public void testSpicifyVersionInCLICall() throws Exception {
// Setup the environment
setupVersionedTool();
DumbSlave slave = r.createSlave();
FreeStyleProject project = setupJobWithVersionParam(slave);
CaptureEnvironmentBuilder recorder = new CaptureEnvironmentBuilder();
project.getBuildersList().add(recorder);

// Create CLI & run command
command = new CLICommandInvoker(r, new BuildCommand());
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.ADMINISTER)
.invokeWithArgs("foo","-p","string=foo","-p","TOOL_VERSION=test");
assertThat(result, succeeded());

// Check the job
Queue.Item q = r.jenkins.getQueue().getItem(project);
Thread.sleep(5000);
q.getFuture();
}
}

0 comments on commit da07afb

Please sign in to comment.