Skip to content

Commit

Permalink
Use a container that includes procps to fix WithContainerStepTest#stop
Browse files Browse the repository at this point in the history
  • Loading branch information
dwnusbaum committed Jun 21, 2022
1 parent 84bea2a commit b848a6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ private static class Decorator extends LauncherDecorator implements Serializable
@Override public void kill(Map<String,String> modelEnvVars) throws IOException, InterruptedException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String executable = getExecutable();
// For this code to be able to successfully kill processes:
// 1: The image must contain `ps`, which notably excludes slim variants of Debian.
// 2. The version of `ps` being used must support `-o command`. Busybox does not (so no Alpine!).
// `-o args` seems to be a more portable equivalent, but even then, see JENKINS-52881.
// 3. The version of `ps` being used must support the `e` output modifier to include environment
// variables in the command's output. Otherwise, the output only includes `jsc=<cookie here>` and
// `JENKINS_SERVER_COOKIE=$jsc`, but the output must include `JENKINS_SERVER_COOKIE=<cookie here>
// for this code to work.
// In practice, this means that this code only works with images that include procps.
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) {
throw new IOException("failed to run ps");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public class WithContainerStepTest {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" withDockerContainer('httpd:2.4.12') {\n" +
" withDockerContainer('ubuntu:kinetic-20220602') {\n" +
" 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" +
" }\n" +
"}", true));
Expand Down

0 comments on commit b848a6e

Please sign in to comment.