/** * Actually build a project, passing in parameters where appropriate * * @param project * @return */ protected final boolean performBuildProject(AbstractProject<?, ?> project) { if (!project.hasPermission(AbstractProject.BUILD)) { LOGGER.log(Level.WARNING, "Insufficient permission to build job '" + project.getName() + "'"); return false; } if (action.equals(BuildAction.POLL_SCM)) { project.schedulePolling(); return true; } // no user parameters provided, just build it if (param == null) { project.scheduleBuild(new Cause.UserIdCause()); return true; } ParametersDefinitionProperty pp = (ParametersDefinitionProperty) project.getProperty(ParametersDefinitionProperty.class); // project does not except any parameters, just build it if (pp == null) { project.scheduleBuild(new Cause.UserIdCause()); return true; } List<ParameterDefinition> parameterDefinitions = pp.getParameterDefinitions(); List<ParameterValue> values = new ArrayList<ParameterValue>(); for (ParameterDefinition paramDef : parameterDefinitions) { if (!(paramDef instanceof StringParameterDefinition)) { // TODO add support for other parameter types values.add(paramDef.getDefaultParameterValue()); continue; } StringParameterDefinition stringParamDef = (StringParameterDefinition) paramDef; ParameterValue value; // Did user supply this parameter? if (param.containsKey(paramDef.getName())) { value = stringParamDef.createValue(param.get(stringParamDef.getName())); } else { // No, then use the default value value = stringParamDef.createValue(stringParamDef.getDefaultValue()); } values.add(value); } Jenkins.getInstance().getQueue().schedule(pp.getOwner(), 1, new ParametersAction(values)); return true; }
/** * 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")); } }