@Override /* * We need this for JENKINS-26143 -- reflective creation cannot handle setChoices(Object). See that method for context. */ public ParameterDefinition newInstance(@Nullable StaplerRequest req, @Nonnull JSONObject formData) throws FormException { String name = formData.getString("name"); String desc = formData.getString("description"); String choiceText = formData.getString("choices"); return new ChoiceParameterDefinition(name, choiceText, desc); }
@Override public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) { if (defaultValue instanceof StringParameterValue) { StringParameterValue value = (StringParameterValue) defaultValue; return new ChoiceParameterDefinition(getName(), choices, value.value, getDescription()); } else { return this; } }
@Override public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) { if (defaultValue instanceof StringParameterValue) { StringParameterValue value = (StringParameterValue) defaultValue; return new ChoiceParameterDefinition(getName(), choices, value.value, getDescription()); } else { return this; } }
@Override public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) { if (defaultValue instanceof StringParameterValue) { StringParameterValue value = (StringParameterValue) defaultValue; return new ChoiceParameterDefinition(getName(), choices, value.value, getDescription()); } else { return this; } }
@Issue("JENKINS-26143") @Test public void testChoiceParameterSnippetizer() throws Exception { //new SnippetizerTester(r).assertGenerateSnippet(); new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(Arrays.asList(new ParametersDefinitionProperty(new ChoiceParameterDefinition("paramName", new String[] { "foo", "bar", "baz" }, "")))), "properties([parameters([choice(choices: ['foo', 'bar', 'baz'], description: '', name: 'paramName')])])"); }
@Issue("JENKINS-22568") @Test @Ignore("TODO use docker-fixtures for a reproducible test case") public void pollingWithChoiceParametersWithOutCurlyBraces() throws Exception { FreeStyleProject p = r.createFreeStyleProject(); String repo = "https://svn.jenkins-ci.org/"; String path = "trunk/hudson/test-projects/trivial-maven/src/test/java/test"; p.setScm(new SubversionSCM("${REPO}" + path)); ParametersDefinitionProperty property = new ParametersDefinitionProperty(new ChoiceParameterDefinition("REPO", new String[] {repo, "test"}, "")); p.addProperty(property); FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserIdCause(), new ParametersAction(new StringParameterValue("REPO", repo))).get(); r.assertBuildStatus(Result.SUCCESS,b); assertTrue(b.getWorkspace().child("AppTest.java").exists()); // as a baseline, this shouldn't detect any change TaskListener listener = r.createTaskListener(); PollingResult poll = p.poll(listener); assertFalse("Polling shouldn't have any changes.", poll.hasChanges()); }