diff --git a/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate.java b/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate.java old mode 100755 new mode 100644 index fb04725..53be6a6 --- a/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate.java +++ b/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate.java @@ -35,7 +35,8 @@ public class DockerSwarmAgentTemplate implements Describable envHashMap = new HashMap(){{ + put("\\%DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET\\%",getAgentSecret(computer)); + put("\\%DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL\\%",getAgentJarUrl(configuration)); + put("\\%DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JNLP_URL\\%",getAgentJnlpUrl(computer, configuration)); + put("\\%DOCKER_SWARM_PLUGIN_JENKINS_AGENT_NAME\\%",getAgentName(computer)); + + }}; + for (String envVarString: envHashMap.keySet()){ + System.out.println("Replacing: "+ envVarString + " with: "+envHashMap.get(envVarString)); + command = command.replaceAll(envVarString, envHashMap.get(envVarString)); + System.out.println("Command: "+ command); + } + ArrayList finalCommand = new ArrayList(); + String [] windowsCommand = dockerSwarmAgentTemplate.getWindowsCommandConfig(command); + for (String windowsCommandSegment: windowsCommand){ + if(windowsCommandSegment.equals("${unixCommand}")){ + for(String unixCommandSegment: dockerSwarmAgentTemplate.getUnixCommandConfig()){ + finalCommand.add(unixCommandSegment); + } + } else{ + finalCommand.add(windowsCommandSegment); + } + } + + launchContainer(finalCommand.toArray(new String[0]), configuration, envVars, dockerSwarmAgentTemplate.getWorkingDir(), dockerSwarmAgentTemplate.getUser(), dockerSwarmAgentTemplate, listener, computer, dockerSwarmAgentTemplate.getHostsConfig()); } else { - launchContainer(dockerSwarmAgentTemplate.getCommandConfig(), configuration, envVars, + launchContainer(dockerSwarmAgentTemplate.getUnixCommandConfig(), configuration, envVars, dockerSwarmAgentTemplate.getWorkingDir(), dockerSwarmAgentTemplate.getUser(), dockerSwarmAgentTemplate, listener, computer, dockerSwarmAgentTemplate.getHostsConfig()); } diff --git a/src/main/resources/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate/config.jelly b/src/main/resources/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate/config.jelly index 1651f06..1ae2b31 100755 --- a/src/main/resources/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate/config.jelly @@ -9,8 +9,11 @@ - - + + + + +