Skip to content

Commit ea5e5e8

Browse files
authored
Merge pull request #257 from dwnusbaum/test-fixes
Fix WithContainerStepTest.stop and WithContainerStepTest.death
2 parents c727e97 + b848a6e commit ea5e5e8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,15 @@ private static class Decorator extends LauncherDecorator implements Serializable
350350
@Override public void kill(Map<String,String> modelEnvVars) throws IOException, InterruptedException {
351351
ByteArrayOutputStream baos = new ByteArrayOutputStream();
352352
String executable = getExecutable();
353+
// For this code to be able to successfully kill processes:
354+
// 1: The image must contain `ps`, which notably excludes slim variants of Debian.
355+
// 2. The version of `ps` being used must support `-o command`. Busybox does not (so no Alpine!).
356+
// `-o args` seems to be a more portable equivalent, but even then, see JENKINS-52881.
357+
// 3. The version of `ps` being used must support the `e` output modifier to include environment
358+
// variables in the command's output. Otherwise, the output only includes `jsc=<cookie here>` and
359+
// `JENKINS_SERVER_COOKIE=$jsc`, but the output must include `JENKINS_SERVER_COOKIE=<cookie here>
360+
// for this code to work.
361+
// In practice, this means that this code only works with images that include procps.
353362
if (getInner().launch().cmds(executable, "exec", container, "ps", "-A", "-o", "pid,command", "e").stdout(baos).quiet(true).start().joinWithTimeout(DockerClient.CLIENT_TIMEOUT, TimeUnit.SECONDS, listener) != 0) {
354363
throw new IOException("failed to run ps");
355364
}

src/test/java/org/jenkinsci/plugins/docker/workflow/WithContainerStepTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public class WithContainerStepTest {
164164
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
165165
p.setDefinition(new CpsFlowDefinition(
166166
"node {\n" +
167-
" withDockerContainer('httpd:2.4.12') {\n" +
167+
" withDockerContainer('ubuntu:kinetic-20220602') {\n" +
168168
" sh 'trap \\'echo got SIGTERM\\' TERM; trap \\'echo exiting; exit 99\\' EXIT; echo sleeping now with JENKINS_SERVER_COOKIE=$JENKINS_SERVER_COOKIE; sleep 999'\n" +
169169
" }\n" +
170170
"}", true));
@@ -185,8 +185,8 @@ public class WithContainerStepTest {
185185
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
186186
p.setDefinition(new CpsFlowDefinition(
187187
"node {\n" +
188-
" withDockerContainer('httpd:2.4.12') {\n" +
189-
" sh \"sleep 5; ps -e -o pid,command | egrep '${pwd tmp: true}/durable-.+/script.sh' | fgrep -v grep | sort -n | tr -s ' ' | cut -d ' ' -f2 | xargs kill -9\"\n" +
188+
" withDockerContainer('httpd:2.4.54-alpine') {\n" +
189+
" sh \"set -e; sleep 5; ps -e -o pid,args | egrep '${pwd tmp: true}/durable-.+/script.sh' | fgrep -v grep | sort -n | tr -s ' ' | cut -d ' ' -f2 | xargs kill -9\"\n" +
190190
" }\n" +
191191
"}", true));
192192
Field hci = BourneShellScript.class.getDeclaredField("HEARTBEAT_CHECK_INTERVAL");

0 commit comments

Comments
 (0)