|
31 | 31 | import hudson.model.Node; |
32 | 32 | import hudson.util.ArgumentListBuilder; |
33 | 33 | import hudson.util.VersionNumber; |
34 | | -import org.jenkinsci.plugins.docker.commons.fingerprint.ContainerRecord; |
35 | | - |
36 | | -import javax.annotation.CheckForNull; |
37 | | -import javax.annotation.Nonnull; |
38 | 34 | import java.io.BufferedReader; |
39 | 35 | import java.io.ByteArrayOutputStream; |
40 | 36 | import java.io.IOException; |
|
44 | 40 | import java.text.ParseException; |
45 | 41 | import java.text.SimpleDateFormat; |
46 | 42 | import java.util.ArrayList; |
| 43 | +import java.util.Arrays; |
47 | 44 | import java.util.Collection; |
48 | 45 | import java.util.Collections; |
49 | 46 | import java.util.Date; |
50 | | -import java.util.Map; |
51 | 47 | import java.util.List; |
52 | | -import java.util.Arrays; |
| 48 | +import java.util.Map; |
53 | 49 | import java.util.StringTokenizer; |
54 | 50 | import java.util.concurrent.TimeUnit; |
55 | 51 | import java.util.logging.Level; |
56 | 52 | import java.util.logging.Logger; |
57 | 53 | import java.util.regex.Matcher; |
58 | 54 | import java.util.regex.Pattern; |
| 55 | +import javax.annotation.CheckForNull; |
| 56 | +import javax.annotation.Nonnull; |
| 57 | +import org.apache.commons.lang.StringUtils; |
| 58 | +import org.jenkinsci.plugins.docker.commons.fingerprint.ContainerRecord; |
59 | 59 | import org.jenkinsci.plugins.docker.commons.tools.DockerTool; |
60 | 60 | import org.kohsuke.accmod.Restricted; |
61 | 61 | import org.kohsuke.accmod.restrictions.NoExternalUse; |
@@ -106,7 +106,12 @@ public DockerClient(@Nonnull Launcher launcher, @CheckForNull Node node, @CheckF |
106 | 106 | public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNull String args, @CheckForNull String workdir, @Nonnull Map<String, String> volumes, @Nonnull Collection<String> volumesFromContainers, @Nonnull EnvVars containerEnv, @Nonnull String user, @Nonnull String... command) throws IOException, InterruptedException { |
107 | 107 | ArgumentListBuilder argb = new ArgumentListBuilder(); |
108 | 108 |
|
109 | | - argb.add("run", "-t", "-d", "-u", user); |
| 109 | + argb.add("run", "-t", "-d"); |
| 110 | + |
| 111 | + // Username might be empty because we are running on Windows |
| 112 | + if (StringUtils.isNotEmpty(user)) { |
| 113 | + argb.add("-u", user); |
| 114 | + } |
110 | 115 | if (args != null) { |
111 | 116 | argb.addTokenized(args); |
112 | 117 | } |
@@ -306,6 +311,10 @@ private LaunchResult launch(@CheckForNull @Nonnull EnvVars launchEnv, boolean qu |
306 | 311 | * @return a {@link String} containing the <strong>uid:gid</strong>. |
307 | 312 | */ |
308 | 313 | public String whoAmI() throws IOException, InterruptedException { |
| 314 | + if (!launcher.isUnix()) { |
| 315 | + // Windows does not support username |
| 316 | + return ""; |
| 317 | + } |
309 | 318 | ByteArrayOutputStream userId = new ByteArrayOutputStream(); |
310 | 319 | launcher.launch().cmds("id", "-u").quiet(true).stdout(userId).start().joinWithTimeout(CLIENT_TIMEOUT, TimeUnit.SECONDS, launcher.getListener()); |
311 | 320 |
|
@@ -367,6 +376,6 @@ public List<String> getVolumes(@Nonnull EnvVars launchEnv, String containerID) t |
367 | 376 | if (volumes.isEmpty()) { |
368 | 377 | return Collections.emptyList(); |
369 | 378 | } |
370 | | - return Arrays.asList(volumes.split("\\n")); |
| 379 | + return Arrays.asList(volumes.replace("\\", "/").split("\\n")); |
371 | 380 | } |
372 | 381 | } |
0 commit comments