示例#1
0
  /**
   * 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("../../");
    }
  }
示例#2
0
  /**
   * 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("../../");
  }
示例#3
0
 /**
  * Handles the rebuild request and redirects to parameterized and non parameterized build when
  * needed.
  *
  * @param request StaplerRequest the request.
  * @param response StaplerResponse the response handler.
  * @throws IOException in case of Stapler issues
  * @throws ServletException if something unfortunate happens.
  * @throws InterruptedException if something unfortunate happens.
  */
 public void doIndex(StaplerRequest request, StaplerResponse response)
     throws IOException, ServletException, InterruptedException {
   AbstractBuild currentBuild = request.findAncestorObject(AbstractBuild.class);
   if (currentBuild != null) {
     ParametersAction paramAction = currentBuild.getAction(ParametersAction.class);
     if (paramAction != null) {
       response.sendRedirect(PARAMETERIZED_URL);
     } else {
       nonParameterizedRebuild(currentBuild, response);
     }
   }
 }