From 055031e873b691dadc63c63a3cc4857b97e99d20 Mon Sep 17 00:00:00 2001 From: Alvaro Rausell Guiard Date: Wed, 6 Apr 2022 16:49:12 +0100 Subject: [PATCH] Add support for Windows commands --- .../swarm/DockerSwarmAgentTemplate.java | 27 ++++++++---- .../swarm/DockerSwarmComputerLauncher.java | 42 ++++++++++++------- .../DockerSwarmAgentTemplate/config.jelly | 7 +++- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate.java b/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate.java index b2c60dcc..f0ca5cde 100755 --- 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 6450907e..6092ad53 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 @@ - - + + + + +