Skip to content

Commit 9beedd7

Browse files
author
Stefan Lengauer
committed
- fix process detection for windows container
1 parent a73d192 commit 9beedd7

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,14 @@ public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNu
140140
}
141141

142142
public List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String containerId) throws IOException, InterruptedException {
143-
LaunchResult result = launch(launchEnv, false, "top", containerId, "-eo", "pid,comm");
143+
LaunchResult result;
144+
boolean iswin = !launcher.isUnix();
145+
if (iswin){
146+
result = launch(launchEnv, false, "top", containerId);
147+
} else {
148+
// comm,pid so that the output matches the windows columns
149+
result = launch(launchEnv, false, "top", containerId, "-eo", "comm,pid");
150+
}
144151
if (result.getStatus() != 0) {
145152
throw new IOException(String.format("Failed to run top '%s'. Error: %s", containerId, result.getErr()));
146153
}
@@ -154,8 +161,8 @@ public List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String cont
154161
if (stringTokenizer.countTokens() < 2) {
155162
throw new IOException("Unexpected `docker top` output : "+line);
156163
}
157-
stringTokenizer.nextToken(); // PID
158-
processes.add(stringTokenizer.nextToken()); // COMMAND
164+
// Windows containers are started without the .exe suffix to cat but top returns cat.exe
165+
processes.add(iswin ? stringTokenizer.nextToken().replace(".exe","") : stringTokenizer.nextToken()); // COMMAND
159166
}
160167
}
161168
return processes;

0 commit comments

Comments
 (0)