From 942f78663d94b2df7794f2abcae682c68abef022 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 15 Feb 2025 22:38:47 -0700 Subject: [PATCH] Use `docker ps` to detect absence of docker permissions The plugin BOM agents seem to have the `docker` command available but the user running the agent is not authorized to use the `docker` command. Previously that was detected by calling `docker ps` and detecting the failure. Restores a change made in * https://github.com/jenkinsci/docker-workflow-plugin/pull/331 Testing done Confirmed that I could see the same failure on a local computer as is seen on https://ci.jenkins.io/job/Tools/job/bom/job/master/3968/testReport/org.jenkinsci.plugins.docker.workflow/DockerDSLTest/ The computer had Docker CE installed by the specific user running the test did not have permission to access Docker. Prior to this change, the tests failed with the message: CANNOT CONNECT TO THE DOCKER DAEMON AT UNIX:///VAR/RUN/DOCKER.SOCK. IS THE DOCKER DAEMON RUNNING? After making this change, the tests pass on that computer with the specific user that does not have permission to access Docker. --- .../jenkinsci/plugins/docker/workflow/DockerTestUtil.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/jenkinsci/plugins/docker/workflow/DockerTestUtil.java b/src/test/java/org/jenkinsci/plugins/docker/workflow/DockerTestUtil.java index 445b41b9f..0469cd727 100644 --- a/src/test/java/org/jenkinsci/plugins/docker/workflow/DockerTestUtil.java +++ b/src/test/java/org/jenkinsci/plugins/docker/workflow/DockerTestUtil.java @@ -74,8 +74,14 @@ public static void assumeDocker(DockerOsMode osMode) throws Exception { public static void assumeDocker(DockerOsMode osMode, VersionNumber minimumVersion) throws Exception { Launcher.LocalLauncher localLauncher = new Launcher.LocalLauncher(StreamTaskListener.NULL); try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); int status = localLauncher + .launch() + .cmds(DockerTool.getExecutable(null, null, null, null), "ps") + .start() + .joinWithTimeout(DockerClient.CLIENT_TIMEOUT, TimeUnit.SECONDS, localLauncher.getListener()); + Assume.assumeTrue("Docker working", status == 0); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + status = localLauncher .launch() .cmds(DockerTool.getExecutable(null, null, null, null), "version", "-f", "{{.Server.Os}}") .stdout(out)