Skip to content
Permalink
Browse files
Merge pull request #38 from jglick/diag-pwd-JENKINS-33510
[JENKINS-33510] At least clearly diagnose failure to set CWD
  • Loading branch information
ndeloof committed Mar 16, 2016
2 parents d12dd88 + e1a32fc commit e07ea8d7625a42a892d6f05810e331c69ea8af9a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
@@ -146,7 +146,7 @@ public static class Execution extends AbstractStepExecutionImpl {
DockerFingerprints.addRunFacet(dockerClient.getContainerRecord(env, container), run);
ImageAction.add(step.image, run);
getContext().newBodyInvoker().
withContext(BodyInvoker.mergeLauncherDecorators(getContext().get(LauncherDecorator.class), new Decorator(container, envHost))).
withContext(BodyInvoker.mergeLauncherDecorators(getContext().get(LauncherDecorator.class), new Decorator(container, envHost, ws))).
withCallback(new Callback(container, toolName)).
start();
return false;
@@ -171,16 +171,27 @@ private static class Decorator extends LauncherDecorator implements Serializable
private static final long serialVersionUID = 1;
private final String container;
private final String[] envHost;
private final String ws;

Decorator(String container, EnvVars envHost) {
Decorator(String container, EnvVars envHost, String ws) {
this.container = container;
this.envHost = Util.mapToEnv(envHost);
this.ws = ws;
}

@Override public Launcher decorate(Launcher launcher, Node node) {
@Override public Launcher decorate(final Launcher launcher, Node node) {
return new Launcher.DecoratedLauncher(launcher) {
@Override public Proc launch(Launcher.ProcStarter starter) throws IOException {
List<String> prefix = new ArrayList<String>(Arrays.asList("docker", "exec", container, "env"));
if (ws != null) {
FilePath cwd = starter.pwd();
if (cwd != null) {
String path = cwd.getRemote();
if (!path.equals(ws)) {
launcher.getListener().getLogger().println("JENKINS-33510: working directory will be " + ws + " not " + path);
}
}
} // otherwise we are loading an old serialized Decorator
Set<String> envReduced = new TreeSet<String>(Arrays.asList(starter.envs()));
envReduced.removeAll(Arrays.asList(envHost));
prefix.addAll(envReduced);
@@ -215,4 +215,26 @@ public class WithContainerStepTest {
});
}

@Ignore("TODO no fix yet")
@Issue("JENKINS-33510")
@Test public void cd() throws Exception {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
DockerTestUtil.assumeDocker();
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" withDockerContainer('ubuntu') {\n" +
" sh 'mkdir subdir && echo somecontent > subdir/file'\n" +
" dir('subdir') {\n" +
" sh 'pwd; tr \"a-z\" \"A-Z\" < file'\n" +
" }\n" +
" }\n" +
"}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("SOMECONTENT", b);
}
});
}

}

0 comments on commit e07ea8d

Please sign in to comment.