|
38 | 38 | import hudson.util.Secret;
|
39 | 39 | import hudson.util.StreamTaskListener;
|
40 | 40 | import java.io.File;
|
| 41 | +import java.nio.file.Files; |
| 42 | +import java.nio.file.Path; |
41 | 43 | import java.util.Collection;
|
42 | 44 | import java.util.Collections;
|
43 | 45 | import java.util.logging.Level;
|
|
69 | 71 | import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution;
|
70 | 72 | import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
|
71 | 73 | import org.junit.Assume;
|
| 74 | +import static org.junit.Assert.assertTrue; |
72 | 75 | import static org.junit.Assume.assumeTrue;
|
73 | 76 | import org.junit.ClassRule;
|
74 | 77 | import org.junit.Ignore;
|
@@ -515,4 +518,37 @@ private static final class Execution extends SynchronousNonBlockingStepExecution
|
515 | 518 | }
|
516 | 519 | });
|
517 | 520 | }
|
| 521 | + |
| 522 | + @Issue("JENKINS-74912") |
| 523 | + @Test public void windowsRunningWindowsContainerAlternateDriveWorkspace() { |
| 524 | + // Run with another drive ("D") if it is mounted |
| 525 | + story.addStep(new Statement() { |
| 526 | + @Override public void evaluate() throws Throwable { |
| 527 | + DockerTestUtil.assumeWindows(); |
| 528 | + DockerTestUtil.assumeDocker(DockerTestUtil.DockerOsMode.WINDOWS); |
| 529 | + DockerTestUtil.assumeDrive('D'); |
| 530 | + |
| 531 | + // Manually create instead of using a Rule since not all executions will have the D drive mounted |
| 532 | + Path tempDir = Files.createTempDirectory(Path.of("D:/"), "j ws"); |
| 533 | + tempDir.toFile().deleteOnExit(); |
| 534 | + |
| 535 | + // Kernel must match when running Windows containers on docker on Windows |
| 536 | + String releaseTag = DockerTestUtil.getWindowsImageTag(); |
| 537 | + |
| 538 | + WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj"); |
| 539 | + p.setDefinition(new CpsFlowDefinition( |
| 540 | + "node {\n" + |
| 541 | + " ws('" + tempDir.toString().replace("\\", "\\\\") + "') {\n" + |
| 542 | + " withDockerContainer('mcr.microsoft.com/windows/nanoserver:" + releaseTag + "') { \n" + |
| 543 | + " bat 'echo bar > foo.txt' \n" + |
| 544 | + " bat 'echo ran OK' \n" + |
| 545 | + " }\n" + |
| 546 | + " }\n" + |
| 547 | + "}", true)); |
| 548 | + WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)); |
| 549 | + story.j.assertLogContains("ran OK", b); |
| 550 | + assertTrue("Mounted workspace contains foo.txt", tempDir.resolve("foo.txt").toFile().exists()); |
| 551 | + } |
| 552 | + }); |
| 553 | + } |
518 | 554 | }
|
0 commit comments