From a6b2303cc3563e0922248ad87c9e14d9c9b5d9e9 Mon Sep 17 00:00:00 2001 From: Nikola Naydenov Date: Thu, 8 Oct 2020 18:27:54 +0300 Subject: [PATCH] adding regex to filter docker container Id and avoid additional messages from docker run --- .../plugins/docker/workflow/WithContainerStep.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 ebbfd68a3..baaecddfc 100644 --- a/src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java +++ b/src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java @@ -73,6 +73,9 @@ import java.util.logging.Logger; import java.util.stream.Collectors; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class WithContainerStep extends AbstractStepImpl { private static final Logger LOGGER = Logger.getLogger(WithContainerStep.class.getName()); @@ -196,6 +199,13 @@ 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); + Pattern cid_rx = Pattern.compile("[0-9,a-f]{64}"); + Matcher cid_mr = cid_rx.matcher(container); + + if (cid_mr.find()) { + container = cid_mr.group(); + } + final List ps = dockerClient.listProcess(env, container); if (!ps.contains(command)) { listener.error(