Skip to content

[JENKINS-74912] Fix Docker Windows non-C workspaces #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,24 @@
}
} else {
listener.getLogger().println(node.getDisplayName() + " does not seem to be running inside a container");
volumes.put(ws, ws);
volumes.put(tmp, tmp);

if (launcher.isUnix()) {

Check warning on line 196 in src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 196 is only partially covered, one branch is missing
volumes.put(ws, ws);
volumes.put(tmp, tmp);
} else {
char wsDrive = Character.toUpperCase(ws.charAt(0));

if (wsDrive != 'C') {
listener.getLogger().println("Detected workspace on drive '" + wsDrive + "'. Mounting entire drive.");

// JENKINS-74912 Docker for windows does not support mounting non-root non-C volumes
// Target mount must not end with '/'. Note tmp will be on the same drive.
volumes.put(wsDrive + ":/", wsDrive + ":");
} else {
volumes.put(ws, ws);
volumes.put(tmp, tmp);

Check warning on line 210 in src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 200-210 are not covered by tests
}
}
}

String command = launcher.isUnix() ? "cat" : "cmd.exe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import hudson.util.Secret;
import hudson.util.StreamTaskListener;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.logging.Level;
Expand Down Expand Up @@ -69,6 +71,7 @@
import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.Assume;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import org.junit.ClassRule;
import org.junit.Ignore;
Expand Down Expand Up @@ -515,4 +518,37 @@ private static final class Execution extends SynchronousNonBlockingStepExecution
}
});
}

@Issue("JENKINS-74912")
@Test public void windowsRunningWindowsContainerAlternateDriveWorkspace() {
// Run with another drive ("D") if it is mounted
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
DockerTestUtil.assumeWindows();
DockerTestUtil.assumeDocker(DockerTestUtil.DockerOsMode.WINDOWS);
DockerTestUtil.assumeDrive('D');

// Manually create instead of using a Rule since not all executions will have the D drive mounted
Path tempDir = Files.createTempDirectory(Path.of("D:/"), "j ws");
tempDir.toFile().deleteOnExit();

// Kernel must match when running Windows containers on docker on Windows
String releaseTag = DockerTestUtil.getWindowsImageTag();

WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" ws('" + tempDir.toString().replace("\\", "\\\\") + "') {\n" +
" withDockerContainer('mcr.microsoft.com/windows/nanoserver:" + releaseTag + "') { \n" +
" bat 'echo bar > foo.txt' \n" +
" bat 'echo ran OK' \n" +
" }\n" +
" }\n" +
"}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("ran OK", b);
assertTrue("Mounted workspace contains foo.txt", tempDir.resolve("foo.txt").toFile().exists());
}
});
}
}
Loading