Skip to content

Commit d127f81

Browse files
committed
Fail tests on CI if Windows symlinks are not enabled
We do not want to fail the test on a developer computer if symlinks are not enabled, but we do want to fail the test if a CI agent on Windows does not have symbolic links enabled.
1 parent 6327441 commit d127f81

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/src/test/java/hudson/model/WindowsUtil.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
package hudson.model;
2626

27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
2729
import java.io.IOException;
2830
import java.nio.file.Files;
2931
import java.nio.file.Path;
@@ -38,6 +40,18 @@ public class WindowsUtil {
3840

3941
private static final AtomicReference<Boolean> symlinkSupported = new AtomicReference<>();
4042

43+
/**
44+
* Fail the test if running in CI and symlinks are not supported.
45+
* We do not want to fail the test on a developer computer if
46+
* symlinks are not enabled, but we do want to fail the test if a
47+
* CI agent on Windows does not have symbolic links enabled.
48+
*/
49+
private static void assertConfiguration(boolean supported) {
50+
if (System.getenv("CI") != null) {
51+
assertTrue(supported, "Jenkins CI configurations must enable symlinks on Windows");
52+
}
53+
}
54+
4155
/**
4256
* Returns true if Windows allows a symbolic link to be created.
4357
*
@@ -48,11 +62,13 @@ public static boolean isWindowsSymlinkSupported() throws IOException {
4862
// Fast path, don't acquire unnecessary lock
4963
Boolean supported = symlinkSupported.get();
5064
if (supported != null) {
65+
assertConfiguration(supported);
5166
return supported;
5267
}
5368
synchronized (WindowsUtil.class) {
5469
supported = symlinkSupported.get();
5570
if (supported != null) {
71+
assertConfiguration(supported);
5672
return supported;
5773
}
5874
Path tempDir = Files.createTempDirectory("symlink-check");
@@ -70,6 +86,7 @@ public static boolean isWindowsSymlinkSupported() throws IOException {
7086
Files.delete(tempDir);
7187
}
7288
}
89+
assertConfiguration(symlinkSupported.get());
7390
return symlinkSupported.get();
7491
}
7592
}

0 commit comments

Comments
 (0)