Skip to content

Commit d5f0cea

Browse files
authored
JENKINS-46636 Fix dir() for older docker
https://issues.jenkins-ci.org/browse/JENKINS-46636 This works around the lack of --workdir for "docker exec" in versions earlier than 17.12. It wraps an additional shell around the sh() command which issues a "cd" before delegating.
1 parent 50ad50b commit d5f0cea

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ private static class Decorator extends LauncherDecorator implements Serializable
252252
prefix.add("--workdir");
253253
prefix.add(path);
254254
} else {
255-
launcher.getListener().getLogger().println("Docker version is older than 17.12, working directory will be " + ws + " not " + path);
255+
String safePath = path.replace("'", "'\"'\"'");
256+
starter.cmds().addAll(0, Arrays.asList("sh", "-c", "cd '" + safePath + "'; \"$@\"", "--"));
256257
}
257258
}
258259
}

0 commit comments

Comments
 (0)