Skip to content
Permalink
Browse files

fix JENKINS-11006 add support for single node and list/array of nodes…

… 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 ad5bc25a23852e8bf7b31499038b438c91d5e248
@@ -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;
@@ -38,6 +39,7 @@
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) {
@@ -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;
}
}
@@ -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;
}
@@ -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.
You can’t perform that action at this time.