Skip to content

Commit

Permalink
[JENKINS-24995] fixed exception when not passing any toollocations
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdfuse committed Oct 5, 2014
1 parent 573ede9 commit e3bcd9c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plugin/src/main/java/hudson/plugins/swarm/PluginImpl.java
Expand Up @@ -5,7 +5,6 @@
import hudson.Util;
import hudson.model.Descriptor.FormException;
import hudson.model.Node;
import hudson.slaves.NodeProperty;
import hudson.slaves.SlaveComputer;
import hudson.tools.ToolDescriptor;
import hudson.tools.ToolInstallation;
Expand All @@ -18,6 +17,7 @@

import jenkins.model.Jenkins;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
Expand Down Expand Up @@ -48,15 +48,19 @@ public void doCreateSlave(StaplerRequest req, StaplerResponse rsp, @QueryParamet

jenkins.checkPermission(SlaveComputer.CREATE);

ToolLocationNodeProperty toolLocationNodeProperty = new ToolLocationNodeProperty(parseToolLocations(toolLocations));
List<ToolLocationNodeProperty> nodeProperties = Lists.newArrayList();
if (StringUtils.isNotBlank(toolLocations)) {
List<ToolLocation> parsedToolLocations = parseToolLocations(toolLocations);
nodeProperties = Lists.newArrayList(new ToolLocationNodeProperty(parsedToolLocations));
}

// try to make the name unique. Swarm clients are often replicated VMs, and they may have the same name.
if (jenkins.getNode(name) != null) {
name = name + '-' + req.getRemoteAddr();
}

SwarmSlave slave = new SwarmSlave(name, "Swarm slave from " + req.getRemoteHost() + " : " + description,
remoteFsRoot, String.valueOf(executors), mode, "swarm " + Util.fixNull(labels), Lists.newArrayList(toolLocationNodeProperty));
SwarmSlave slave = new SwarmSlave(name, "Swarm slave from " + req.getRemoteHost() + " : " + description,
remoteFsRoot, String.valueOf(executors), mode, "swarm " + Util.fixNull(labels), nodeProperties);

// if this still results in a duplicate, so be it
synchronized (jenkins) {
Expand Down

0 comments on commit e3bcd9c

Please sign in to comment.