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

[JENKINS-49372] Support extended-choice-parameter JSON parameter #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
<artifactId>pipeline-model-definition</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>extended-choice-parameter</artifactId>
<version>0.82</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import net.sf.json.JSONObject;

/**
* {@link Trigger} that runs a job periodically with support for parameters.
*
Expand Down Expand Up @@ -62,7 +64,15 @@ private List<ParameterValue> configurePropertyValues(Map<String, String> paramet
if (parameterValues.containsKey(paramDefinition.getName())) {
ParameterizedStaplerRequest request = new ParameterizedStaplerRequest(
parameterValues.get(paramDefinition.getName()));
ParameterValue value = paramDefinition.createValue(request);
ParameterValue value;
if (paramDefinition.getClass().getName().equals("com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition") &&
paramDefinition.getType().equals("PT_JSON")) {
JSONObject jO = new JSONObject();
jO.put("value", parameterValues.get(paramDefinition.getName()));
value = paramDefinition.createValue(request, jO);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like an arbitrary hackaround

} else {
value = paramDefinition.createValue(request);
}
if (value!= null) {
defValues.add(value);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.parameterizedscheduler;

import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition;
import hudson.model.FreeStyleProject;
import hudson.model.Job;
import hudson.model.ParameterDefinition;
Expand Down Expand Up @@ -106,6 +107,30 @@ public void declarative() throws Exception {
assertThat((String) p.getLastCompletedBuild().getAction(ParametersAction.class).getParameter("foo").getValue(), is("bar"));
}

@Test
@Issue("JENKINS-49372")
public void extendedChoiceJson() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty(new ExtendedChoiceParameterDefinition("foo", ExtendedChoiceParameterDefinition.PARAMETER_TYPE_JSON, "",
"", "", "def jsonSlurper = new groovy.json.JsonSlurper()\n" +
"def object = jsonSlurper.parseText('{\"schema\":{\"type\":\"object\",\"title\":\"Car\",\"properties\":{\"make\":{\"type\":\"string\",\"enum\":[\"Toyota\",\"BMW\",\"Honda\",\"Ford\",\"Chevy\",\"VW\"]},\"model\":{\"type\":\"string\"},\"year\":{\"type\":\"integer\",\"enum\":[1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014],\"default\":2008}}}}')\n" +
"return object", "", "", "", "",
"", "", "" , "", "", "",
"", "", "", "", "", "",
"", "", "", "", false, false,
0, "", "")));
assertThat(p.getLastCompletedBuild(), is(nullValue()));
Trigger<Job> t = new ParameterizedTimerTrigger("* * * * *%foo={\"make\":\"Toyota\",\"model\":\"test\",\"year\":2008}");
t.start(p, true);
p.addTrigger(t);
new Cron().doRun();
assertThat(p.isInQueue(), is(true));
r.waitUntilNoActivity();
// Build should complete successfully but will not have any value
assertThat(p.getLastCompletedBuild(), is(notNullValue()));
assertThat(p.getLastCompletedBuild().getAction(ParametersAction.class).getParameter("foo").getValue(), is("{\"make\":\"Toyota\",\"model\":\"test\",\"year\":2008}"));
}

@Test
@Issue("JENKINS-49372")
public void nullValueCreated() throws Exception {
Expand Down