示例#1
0
 /**
  * Method for getting the ParameterValue instance from ParameterDefinition or ParamterAction.
  *
  * @param paramDefProp ParametersDefinitionProperty
  * @param parameterName Name of the Parameter.
  * @param paramAction ParametersAction
  * @param req StaplerRequest
  * @param jo JSONObject
  * @return ParameterValue instance of subclass of ParameterValue
  */
 public ParameterValue getParameterValue(
     ParametersDefinitionProperty paramDefProp,
     String parameterName,
     ParametersAction paramAction,
     StaplerRequest req,
     JSONObject jo) {
   ParameterDefinition paramDef;
   // this is normal case when user try to rebuild a parameterized job.
   if (paramDefProp != null) {
     paramDef = paramDefProp.getParameterDefinition(parameterName);
     if (paramDef != null) {
       // The copy artifact plugin throws an exception when using createValue(req, jo)
       // If the parameter comes from the copy artifact plugin, then use the single argument
       // createValue
       if (jo.toString().contains("BuildSelector")
           || jo.toString().contains("WorkspaceSelector")) {
         SimpleParameterDefinition parameterDefinition =
             (SimpleParameterDefinition) paramDefProp.getParameterDefinition(parameterName);
         return parameterDefinition.createValue(jo.getString("value"));
       }
       return paramDef.createValue(req, jo);
     }
   }
   /*
    * when user try to rebuild a build that was invoked by
    * parameterized trigger plugin in that case ParameterDefinition
    * is null for that parametername that is paased by parameterize
    * trigger plugin,so for handling that scenario, we need to
    * create an instance of that specific ParameterValue with
    * passed parameter value by form.
    *
    * In contrast to all other parameterActions, ListSubversionTagsParameterValue uses "tag" instead of "value"
    */
   if (jo.containsKey("value")) {
     return cloneParameter(paramAction.getParameter(parameterName), jo.getString("value"));
   } else {
     return cloneParameter(paramAction.getParameter(parameterName), jo.getString("tag"));
   }
 }