Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/java/com/sonyericsson/rebuild/RebuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void doIndex(StaplerRequest request, StaplerResponse response) throws IOE
Run currentBuild = request.findAncestorObject(Run.class);
if (currentBuild != null) {
ParametersAction paramAction = currentBuild.getAction(ParametersAction.class);
if (paramAction != null) {
if (paramAction != null && paramAction.getParameters().size() > 0) {
RebuildSettings settings = (RebuildSettings)getProject().getProperty(RebuildSettings.class);
if (settings != null && settings.getAutoRebuild()) {
parameterizedRebuild(currentBuild, response);
Expand Down Expand Up @@ -254,6 +254,7 @@ public void nonParameterizedRebuild(Run currentBuild, StaplerResponse
getProject().checkPermission(Item.BUILD);

List<Action> actions = constructRebuildCause(build, null);
fillOtherBuildActions(currentBuild, actions);
Hudson.getInstance().getQueue().schedule((Queue.Task) currentBuild.getParent(), 0, actions);
response.sendRedirect("../../");
}
Expand Down Expand Up @@ -298,6 +299,7 @@ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws Servl
}

List<Action> actions = constructRebuildCause(build, new ParametersAction(values));
fillOtherBuildActions(build, actions);
Hudson.getInstance().getQueue().schedule((Queue.Task) build.getParent(), 0, actions);

rsp.sendRedirect("../../");
Expand Down Expand Up @@ -487,4 +489,18 @@ public RebuildParameterPage getRebuildParameterPage(ParameterValue value) {
// So Jelly fallback could occur.
return null;
}

/**
* Method for copying of old build parameters (such as git revision from git plugin)
*
* @param build old build for parameters extraction
* @param actions list for filling
*/
private void fillOtherBuildActions(Run build, List<Action> actions) {
for (Action a: build.getActions()) {
if (!(a instanceof CauseAction) && !(a instanceof ParametersAction)) {
actions.add(a);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really unsafe, because there are many plugins contributing actions as metadata.
Such copying may potentially cause a duplication of data with errorneous results in plugins

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;

Expand Down Expand Up @@ -393,6 +394,55 @@ public void testRebuildSupportedUnknownParameterValue() throws Exception {
page.asText().contains("This is a mark for test"));
}

/**
* Treats build as non-parameterized if it has empty ParametersAction
*
* @throws Exception
* Exception
*/
public void testStartRebuildWithEmptyParametersAction()
throws Exception {
FreeStyleProject project = createFreeStyleProject();

project.scheduleBuild2(0, new Cause.UserIdCause(),
new ParametersAction())
.get();
HtmlPage page = createWebClient().getPage(project,
"1");
page.getAnchorByText("Rebuild").click();

assertEquals(2, project.getBuilds().size());
assertBuildStatusSuccess(project.getLastBuild());
}

/**
* Creates a new freestyle project and build with an non-parameter action.
* Verify that rebuild has a copy of this action.
*
* @throws Exception
* Exception
*/
public void testCopyingUnknownActionToNewBuild() throws Exception {
FreeStyleProject project = createFreeStyleProject();

Action action = new SupportedUnknownAction();
Build build = project.scheduleBuild2(0, new Cause.RemoteCause("host", "note"), action).get();

while (project.isBuilding()) {
Thread.sleep(DELAY);
}

HtmlPage page = createWebClient().getPage(build);
page.getAnchorByText("Rebuild").click();

assertEquals(2, project.getBuilds().size());
assertBuildStatusSuccess(project.getLastBuild());

SupportedUnknownAction rebuildAction =
project.getLastBuild().getAction(SupportedUnknownAction.class);
assertNotNull(rebuildAction);
}

/**
* A parameter value rebuild plugin does not know.
*/
Expand Down Expand Up @@ -480,6 +530,14 @@ public String getDisplayName() {

}

public static class SupportedUnknownAction implements Action {
private static final long serialVersionUID = 1014662680565914673L;

public String getUrlName() { return "/example"; }
public String getDisplayName() { return "unknown action"; }
public String getIconFileName() { return "icon.png"; }
}

/**
* Provides a view for {@link SupportedUnknownParameterValue} when
* rebuilding.
Expand Down