/** * Saves the form to the configuration and disk. * * @param req StaplerRequest * @param rsp StaplerResponse * @throws ServletException if something unfortunate happens. * @throws IOException if something unfortunate happens. * @throws InterruptedException if something unfortunate happens. */ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException, InterruptedException { getProject().checkPermission(AbstractProject.BUILD); if (isRebuildAvailable()) { if (!req.getMethod().equals("POST")) { // show the parameter entry form. req.getView(this, "index.jelly").forward(req, rsp); return; } build = req.findAncestorObject(AbstractBuild.class); ParametersDefinitionProperty paramDefProp = build.getProject().getProperty(ParametersDefinitionProperty.class); List<ParameterValue> values = new ArrayList<ParameterValue>(); ParametersAction paramAction = build.getAction(ParametersAction.class); JSONObject formData = req.getSubmittedForm(); if (!formData.isEmpty()) { JSONArray a = JSONArray.fromObject(formData.get("parameter")); for (Object o : a) { JSONObject jo = (JSONObject) o; String name = jo.getString("name"); ParameterValue parameterValue = getParameterValue(paramDefProp, name, paramAction, req, jo); if (parameterValue != null) { values.add(parameterValue); } } } CauseAction cause = new CauseAction(new RebuildCause(build)); Hudson.getInstance() .getQueue() .schedule(build.getProject(), 0, new ParametersAction(values), cause); rsp.sendRedirect("../../"); } }
/** * Call this method while rebuilding non parameterized build. . * * @param currentBuild current build. * @param response current response object. * @throws ServletException if something unfortunate happens. * @throws IOException if something unfortunate happens. * @throws InterruptedException if something unfortunate happens. */ public void nonParameterizedRebuild(AbstractBuild currentBuild, StaplerResponse response) throws ServletException, IOException, InterruptedException { getProject().checkPermission(AbstractProject.BUILD); CauseAction cause = new CauseAction(new RebuildCause(currentBuild)); Hudson.getInstance().getQueue().schedule(currentBuild.getProject(), 0, null, cause); response.sendRedirect("../../"); }
/** * Method will return current project. * * @return currentProject. */ public AbstractProject getProject() { if (build != null) { return build.getProject(); } AbstractProject currentProject = null; StaplerRequest request = Stapler.getCurrentRequest(); if (request != null) { currentProject = request.findAncestorObject(AbstractProject.class); } if (currentProject == null) { throw new NullPointerException("Current Project is null"); } return currentProject; }