Skip to content

Commit 942f786

Browse files
committed
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 * jenkinsci#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.
1 parent 60cec91 commit 942f786

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,14 @@ public static void assumeDocker(DockerOsMode osMode) throws Exception {
7474
public static void assumeDocker(DockerOsMode osMode, VersionNumber minimumVersion) throws Exception {
7575
Launcher.LocalLauncher localLauncher = new Launcher.LocalLauncher(StreamTaskListener.NULL);
7676
try {
77-
ByteArrayOutputStream out = new ByteArrayOutputStream();
7877
int status = localLauncher
78+
.launch()
79+
.cmds(DockerTool.getExecutable(null, null, null, null), "ps")
80+
.start()
81+
.joinWithTimeout(DockerClient.CLIENT_TIMEOUT, TimeUnit.SECONDS, localLauncher.getListener());
82+
Assume.assumeTrue("Docker working", status == 0);
83+
ByteArrayOutputStream out = new ByteArrayOutputStream();
84+
status = localLauncher
7985
.launch()
8086
.cmds(DockerTool.getExecutable(null, null, null, null), "version", "-f", "{{.Server.Os}}")
8187
.stdout(out)

0 commit comments

Comments
 (0)