Skip to content

Commit

Permalink
[FIXED JENKINS-24796] Add option for specifying workspace directory
Browse files Browse the repository at this point in the history
  • Loading branch information
vjuranek committed Sep 22, 2014
1 parent 8413a4b commit 208edd5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
25 changes: 18 additions & 7 deletions src/main/java/org/jenkinsci/plugins/radargun/RadarGunBuilder.java
Expand Up @@ -4,8 +4,10 @@
import hudson.CopyOnWrite;
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Launcher.ProcStarter;
import hudson.Util;
import hudson.model.BuildListener;
import hudson.model.StreamBuildListener;
import hudson.model.AbstractBuild;
Expand Down Expand Up @@ -35,6 +37,7 @@
import org.jenkinsci.plugins.radargun.config.ScriptSource;
import org.jenkinsci.plugins.radargun.model.Node;
import org.jenkinsci.plugins.radargun.model.NodeList;
import org.jenkinsci.plugins.radargun.util.Resolver;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

Expand All @@ -47,15 +50,17 @@ public class RadarGunBuilder extends Builder {
private final NodeSource nodeSource;
private final ScriptSource scriptSource;
private final String defaultJvmArgs;
private final String workspacePath;

@DataBoundConstructor
public RadarGunBuilder(String radarGunName, ScenarioSource scenarioSource, NodeSource nodeSource,
ScriptSource scriptSource, String defaultJvmArgs) {
ScriptSource scriptSource, String defaultJvmArgs, String workspacePath) {
this.radarGunName = radarGunName;
this.scenarioSource = scenarioSource;
this.nodeSource = nodeSource;
this.scriptSource = scriptSource;
this.defaultJvmArgs = defaultJvmArgs;
this.workspacePath = Util.fixEmpty(workspacePath);
}

public String getRadarGunName() {
Expand All @@ -78,6 +83,10 @@ public String getDefaultJvmArgs() {
return defaultJvmArgs;
}

public String getWorkspacePath() {
return workspacePath;
}

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
Expand All @@ -88,7 +97,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

NodeList nodes = nodeSource.getNodesList();
List<NodeRunner> nodeRunners = new ArrayList<NodeRunner>(nodes.getNodeCount());

// master start script
RadarGunNodeAction masterAction = new RadarGunNodeAction(build, nodes.getMaster().getHostname(),
"RadarGun master ");
Expand All @@ -105,8 +114,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
Node slave = slaves.get(i);
RadarGunNodeAction slaveAction = new RadarGunNodeAction(build, slave.getHostname());
build.addAction(slaveAction);
String[] slaveCmdLine = scriptSource.getSlaveCmdLine(slave.getHostname(), rgSlaveScript,
String.valueOf(i), buildJvmOptions(slave));
String[] slaveCmdLine = scriptSource.getSlaveCmdLine(slave.getHostname(), rgSlaveScript, String.valueOf(i),
buildJvmOptions(slave));
ProcStarter slaveProcStarter = buildProcStarter(build, launcher, slaveCmdLine, slaveAction.getLogFile());
nodeRunners.add(new NodeRunner(slaveProcStarter, slaveAction));
}
Expand All @@ -132,8 +141,8 @@ private boolean runRGNodes(List<NodeRunner> nodeRunners) throws AbortException {
// wait for processes to be finished
try {
latch.await();
for(Future<Integer> retCode : nodeRetCodes) {
if(retCode.get() != 0) {
for (Future<Integer> retCode : nodeRetCodes) {
if (retCode.get() != 0) {
isSuccess = false;
break;
}
Expand All @@ -157,8 +166,10 @@ private String buildJvmOptions(Node node) {
private ProcStarter buildProcStarter(AbstractBuild<?, ?> build, Launcher launcher, String[] cmdLine, File log)
throws IOException, InterruptedException {
BuildListener logListener = new StreamBuildListener(log, Charset.defaultCharset());
FilePath workspace = workspacePath == null ? build.getWorkspace() : new FilePath(new File(Resolver.buildVar(
build, workspacePath)));
ProcStarter procStarter = launcher.launch().cmds(cmdLine).envs(build.getEnvironment(logListener))
.pwd(build.getWorkspace()).stdout(logListener);
.pwd(workspace).stdout(logListener);
return procStarter;
}

Expand Down
Expand Up @@ -15,10 +15,9 @@
</f:dropdownListBlock>
</j:forEach>
</f:dropdownList>

<j:set var="currNode" value="${instance.nodeSource}" />
<f:dropdownList name="nodeSource" title="Node list"
description="List of the nodes where RadarGun will run">
<f:dropdownList name="nodeSource" title="Node list" description="List of the nodes where RadarGun will run">
<j:forEach var="desc" items="${descriptor.nodeSources}" varStatus="loop">
<f:dropdownListBlock title="${desc.displayName}" value="${loop.index}" selected="${desc==currNode.descriptor}"
staplerClass="${desc.clazz.name}">
Expand All @@ -40,8 +39,14 @@
</j:forEach>
</f:dropdownList>

<f:entry title="Default JVM arguments" field="defaultJvmArgs" description="Defualt JVM args to be passed to master and slave nodes">
<f:textbox />
</f:entry>
<f:advanced>
<f:entry title="Default JVM arguments" field="defaultJvmArgs" description="Defualt JVM args to be passed to master and slave nodes">
<f:textbox />
</f:entry>

<f:entry title="Workspace path" field="workspacePath" description="Path to working directory on master and slaves">
<f:textbox />
</f:entry>
</f:advanced>

</j:jelly>

0 comments on commit 208edd5

Please sign in to comment.