From 1c818cb30daac2e85ca0af0f9e8053532814d559 Mon Sep 17 00:00:00 2001 From: Patrick REDIVO Date: Tue, 21 Jan 2020 09:28:42 +0100 Subject: [PATCH] Issue when cat entrypoint takes time to execute --- .../docker/workflow/WithContainerStep.java | 21 ++++++++++++------- .../docker/workflow/client/DockerClient.java | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java b/src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java index 8c6ccfb1a..46d424daf 100644 --- a/src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java +++ b/src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java @@ -197,15 +197,22 @@ public Execution() { String command = launcher.isUnix() ? "cat" : "cmd.exe"; container = dockerClient.run(env, step.image, step.args, ws, volumes, volumesFromContainers, envReduced, dockerClient.whoAmI(), /* expected to hang until killed */ command); - final List ps = dockerClient.listProcess(env, container); + List ps = dockerClient.listProcess(env, container); + LOGGER.log(Level.FINE, "ps: " + ps); if (!ps.contains(command)) { - listener.error( - "The container started but didn't run the expected command. " + - "Please double check your ENTRYPOINT does execute the command passed as docker run argument, " + - "as required by official docker images (see https://github.com/docker-library/official-images#consistency for entrypoint consistency requirements).\n" + - "Alternatively you can force image entrypoint to be disabled by adding option `--entrypoint=''`."); + //retry once as the 'cat' command might not be called yet, because the entrypoint can take time to process + listener.getLogger().println("Retrying the command, as the 'cat' command might not be called yet..."); + Thread.sleep(2000); + ps = dockerClient.listProcess(env, container); + LOGGER.log(Level.FINE, "ps: " + ps); + if (!ps.contains(command)) { + listener.error( + "The container started but didn't run the expected command. " + + "Please double check your ENTRYPOINT does execute the command passed as docker run argument, " + + "as required by official docker images (see https://github.com/docker-library/official-images#consistency for entrypoint consistency requirements).\n" + + "Alternatively you can force image entrypoint to be disabled by adding option `--entrypoint=''`."); + } } - DockerFingerprints.addRunFacet(dockerClient.getContainerRecord(env, container), run); ImageAction.add(step.image, run); getContext().newBodyInvoker(). diff --git a/src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java b/src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java index 6562606fb..b72cb0799 100644 --- a/src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java +++ b/src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java @@ -144,6 +144,7 @@ public List listProcess(@Nonnull EnvVars launchEnv, @Nonnull String cont if (result.getStatus() != 0) { throw new IOException(String.format("Failed to run top '%s'. Error: %s", containerId, result.getErr())); } + LOGGER.log(Level.FINE, "result: " + result.getOut()); List processes = new ArrayList<>(); try (Reader r = new StringReader(result.getOut()); BufferedReader in = new BufferedReader(r)) {