Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-13644 - Rebuild plugin can't rebuild when using parameters sp…
…ecified by copyartifact

-If the build parameter is of type buildselector (copyartifact plugin), then use the createValue from SimpleParameterDefinition to load the parameter. However, the copyartifact plugin should support the createValue(request, jsonObject). As soon as the copyartifact supports this method, this fix could be disabled.
  • Loading branch information
rinokadijk committed Jan 20, 2013
1 parent 34f88f9 commit b46fdf3
Showing 1 changed file with 37 additions and 47 deletions.
84 changes: 37 additions & 47 deletions src/main/java/com/sonyericsson/rebuild/RebuildAction.java
Expand Up @@ -24,32 +24,18 @@
*/
package com.sonyericsson.rebuild;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;

import hudson.matrix.MatrixRun;
import hudson.model.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import hudson.matrix.MatrixRun;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BooleanParameterValue;
import hudson.model.Cause;
import hudson.model.CauseAction;
import hudson.model.Hudson;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.PasswordParameterValue;
import hudson.model.RunParameterValue;
import hudson.model.StringParameterValue;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
Expand Down Expand Up @@ -167,13 +153,14 @@ public String getUrlName() {
}
}

/**
/**
* Handles the rebuild request and redirects to parameterized
* and non parameterized build when needed.
* @param request StaplerRequest the request.
*
* @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 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
Expand All @@ -194,26 +181,26 @@ public void doIndex(StaplerRequest request, StaplerResponse response) throws
* non parameterized build. .
*
* @param currentBuild current build.
* @param response current response object.
* @throws ServletException if something unfortunate happens.
* @throws IOException if something unfortunate happens.
* @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 {
response) throws ServletException, IOException, InterruptedException {
getProject().checkPermission(AbstractProject.BUILD);
Hudson.getInstance().getQueue().schedule(currentBuild.getProject(), 0, null,
new CauseAction(new Cause.UserIdCause()));
response.sendRedirect("../../");
}
}

/**
* 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 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
Expand All @@ -234,10 +221,9 @@ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws
if (!formData.isEmpty()) {
JSONArray a = JSONArray.fromObject(formData.get("parameter"));
for (Object o : a) {
JSONObject jo = (JSONObject)o;
JSONObject jo = (JSONObject) o;
String name = jo.getString("name");
ParameterValue parameterValue;
parameterValue = getParameterValue(paramDefProp, name, paramAction, req, jo);
ParameterValue parameterValue = getParameterValue(paramDefProp, name, paramAction, req, jo);
if (parameterValue != null) {
values.add(parameterValue);
}
Expand Down Expand Up @@ -281,23 +267,27 @@ public boolean isRebuildAvailable() {
* Method for getting the ParameterValue instance from ParameterDefinition
* or ParamterAction.
*
* @param paramDefProp ParametersDefinitionProperty
* @param paramDefProp ParametersDefinitionProperty
* @param parameterName Name of the Parameter.
* @param paramAction ParametersAction
* @param req StaplerRequest
* @param jo JSONObject
* @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) {
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) {
return paramDef.createValue(req, jo);
if (paramDefProp != null) {
paramDef = paramDefProp.getParameterDefinition(parameterName);
if (paramDef != null) {
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
Expand All @@ -309,9 +299,9 @@ public ParameterValue getParameterValue(ParametersDefinitionProperty paramDefPro
* In contrast to all other parameterActions, ListSubversionTagsParameterValue uses "tag" instead of "value"
*/
if (jo.containsKey("value")) {
return cloneParameter(paramAction.getParameter(parameterName), jo.getString("value"));
return cloneParameter(paramAction.getParameter(parameterName), jo.getString("value"));
} else {
return cloneParameter(paramAction.getParameter(parameterName), jo.getString("tag"));
return cloneParameter(paramAction.getParameter(parameterName), jo.getString("tag"));
}
}

Expand Down

0 comments on commit b46fdf3

Please sign in to comment.