Skip to content

Commit

Permalink
fix JENKINS-11006 add support for single node and list/array of nodes…
Browse files Browse the repository at this point in the history
… via remote trigger, possible defintions are: {name:HOSTN,value:master} or {name:HOSTN,value:[master,host2]} or {labels:master,name:HOSTN}
  • Loading branch information
imod committed Sep 17, 2011
1 parent d945598 commit ad5bc25
Showing 1 changed file with 31 additions and 5 deletions.
Expand Up @@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.kohsuke.stapler.DataBoundConstructor;
Expand All @@ -38,6 +39,7 @@ public class NodeParameterDefinition extends SimpleParameterDefinition {
public final String defaultValue;
private String triggerIfResult;
private boolean allowMultiNodeSelection;
private boolean triggerConcurrentBuilds = false;

@DataBoundConstructor
public NodeParameterDefinition(String name, String description, String defaultValue, List<String> allowedSlaves, String triggerIfResult) {
Expand All @@ -46,11 +48,12 @@ public NodeParameterDefinition(String name, String description, String defaultVa
this.defaultValue = defaultValue;
if ("multiSelectionDisallowed".equals(triggerIfResult)) {
this.allowMultiNodeSelection = false;
}
// else if ("allowMultiSelectionForConcurrentBuilds".equals(triggerIfResult)) {
// }
else {
} else if ("allowMultiSelectionForConcurrentBuilds".equals(triggerIfResult)) {
this.allowMultiNodeSelection = false;
this.triggerConcurrentBuilds = true;
} else {
this.allowMultiNodeSelection = true;
this.triggerConcurrentBuilds = false;
this.triggerIfResult = triggerIfResult;
}
}
Expand Down Expand Up @@ -145,7 +148,23 @@ public String getHelpFile() {

@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
NodeParameterValue value = req.bindJSON(NodeParameterValue.class, jo);
// as String from UI: {"labels":"master","name":"HOSTN"}
// as JSONArray: {"name":"HOSTN","value":["master","host2"]}
// as String from script: {"name":"HOSTN","value":"master"}
final String name = jo.getString("name");
final Object joValue = jo.get("value") == null ? jo.get("labels") : jo.get("value");

List<String> nodes = new ArrayList<String>();
if (joValue instanceof String) {
nodes.add((String) joValue);
} else if (joValue instanceof JSONArray) {
JSONArray ja = (JSONArray) joValue;
for (Object strObj : ja) {
nodes.add((String) strObj);
}
}

NodeParameterValue value = new NodeParameterValue(name, nodes);
value.setDescription(getDescription());
return value;
}
Expand All @@ -157,4 +176,11 @@ public boolean getAllowMultiNodeSelection() {
return allowMultiNodeSelection;
}

/**
* @return the triggerConcurrentBuilds
*/
public boolean isTriggerConcurrentBuilds() {
return triggerConcurrentBuilds;
}

}

0 comments on commit ad5bc25

Please sign in to comment.