ederribeiro
ederribeiro

Reputation: 408

FileNotFound by Jenkins on Windows virtual drive

I have a Jenkins installation (version 1.474) running on a Windows Server Enterprise 2007 machine and I am having a problem when running maven test goal through Jenkins. My test needs to read a txt file in a configured path and I am getting "FileNotFound" exception when running it:

path: file:////X:/TESTIN/file.txt
java.io.FileNotFoundException: X:\TESTIN\file.txt (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:120)
    at java.io.FileInputStream.<init>(FileInputStream.java:79)
    at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
    at br.com.telecomassociates.taalarms.EncoderTest.open(EncoderTest.java:69)
    at br.com.telecomassociates.taalarms.EncoderTest.readFile(EncoderTest.java:48)
    at br.com.telecomassociates.taalarms.EncoderTest.testDecrypt(EncoderTest.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

The problematic point is that this file is referenced through a virtual windows drive:

The file resides physically at D:/TESTOUT/TESTIN/file.txt but we used the above command:

subst X: D:/TESTOUT

and we reference it in our test code by the URI file:///X:/TESTIN/file.txt.

When Jenkins/maven runs it I get a FileNotFound exception, but, when I run the same command using "mvn test" on a Windows command line the file is read correctly:

Runs fine on mvn test

Do you guys have any idea of what may be causing the issue ?

Upvotes: 1

Views: 1363

Answers (1)

ederribeiro
ederribeiro

Reputation: 408

Both @lee-meador and @jtahlborn pointed me in the right direction. My Jenkins is running as a web application inside Tomcat that is running as a service. Turns out that Jenkins was not able to see the X: drive.

To solve the problem i followed an advice fount at https://code.google.com/p/psubst/. I generated a ".reg" file with the following contents:

REGEDIT4 

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices] 
"Z:"="\\??\\D:\\TESTOUT" 

then i executed it and rebooted the machine.

The drive X: is now visible to all users and Jenkins can see it perfectly.

Upvotes: 2

Related Questions