Skip to content
Permalink
Browse files
[Fixes JENKINS-12968] Fixed regression and added test (finally figure…
… out how to!)
  • Loading branch information
swestcott committed Mar 4, 2012
1 parent cd4982c commit 9ebc3cd4342dd5356ce61c5ffaab169b28fdd3fa
@@ -32,6 +32,7 @@
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

@@ -93,18 +94,21 @@ public final void doBuild(StaplerRequest req, StaplerResponse rsp)

BuildAction action = BuildAction.valueOf(buildAction.toUpperCase());
BuildType type = BuildType.valueOf(buildType.toUpperCase());
Builder builder = new Builder(action);

// TODO
String params = req.getParameter("params");
BulkParamProcessor processor = new BulkParamProcessor(params);
Map<String, String> projectParams = processor.getProjectParams();

Builder builder = new Builder(action);
String paramBuild = req.getParameter("paramBuild");
if (paramBuild != null && !paramBuild.isEmpty() && !projectParams.isEmpty()) {
builder.setUserParams(projectParams);
}

String pattern = req.getParameter("pattern");
if (pattern != null && !pattern.isEmpty()) {
builder.setPattern(pattern);
BuildHistory history = Hudson.getInstance().getPlugin(
BuildHistory.class);
BuildHistory history = Hudson.getInstance().getPlugin(BuildHistory.class);
history.add(new BuildHistoryItem(pattern));
}

@@ -24,9 +24,12 @@

package org.jvnet.hudson.plugins.bulkbuilder.model;

import java.util.Map;
import org.junit.Before;
import hudson.model.FreeStyleProject;
import hudson.model.Hudson;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.StringParameterDefinition;
import org.jvnet.hudson.test.HudsonTestCase;
import org.junit.Test;
import org.jvnet.hudson.test.FailureBuilder;
@@ -164,6 +167,23 @@ public void testInsufficientBuildPermission() {
assertEquals(project1NextBuildNumber, project1.getNextBuildNumber());
}

@Test
public void testBuildWithUserSuppliedParameter() throws Exception {
FreeStyleProject paramJob = createFreeStyleProject("paramJob");
StringParameterDefinition spd = new StringParameterDefinition("foo", "bar");
ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(spd);
paramJob.addProperty(pdp);

BulkParamProcessor processor = new BulkParamProcessor("foo=baz");
builder.setPattern("paramJob");
builder.setUserParams(processor.getProjectParams());
assertEquals(1, builder.buildAll());
waitUntilNoActivity();

Map<String, String> buildVariables = paramJob.getLastBuild().getBuildVariables();
assertEquals("baz", buildVariables.get("foo"));
}

private void waitUntilQueueEmpty() {
while(Hudson.getInstance().getQueue().getItems().length > 0) {
// wait for jobs to finish...

0 comments on commit 9ebc3cd

Please sign in to comment.