Command Runner launched java program fail to list files in network folder

I tried to run the following simple Java program using command line builder runner.

public static void main(String[] args) throws IOException {
File[] xf = (new File("b:
")).listFiles();

File(filename).listFiles() returns valid File objects if filename is local resource. If filename is remote (e.g. b:\ drive maps to
host\resource, or
host\resource directly) listFile() returns null.

If I run the exact same program from the command line in the agent's command shell, listFile() behaves correctly regardless of if the filename is local or remote resource.. It only does not work if the java program is launched inside the team city's agent runner.

Any idea what the problem may be?

Albert Lee.

5 comments

I think you should change user account under which agent service is working.

--
Pavel Sher

0

Thanks for the quick response. I was suspecting it may be something to do with security.

I changed the TeamCity agent service's log-on account to my user id instead of "SYSTEM". My user id has Administrator authority.

I submited a job again after the change, restart the teamcity services and it still failed the same way:

: c:\was6\as\java\bin\java.exe -cp . com.ibm.teamcity.tools.WASDriverLoader
: ** isDir =false
: ** isFile=false
: ** exists=false
: fCommitted=b:\
: **Warning: b:\ is an invalid path.
: Exception in thread "main" java.lang.NullPointerException
: at com.ibm.teamcity.tools.WASDriverLoader.getBuildLevel(WASDriverLoader.java:301)
: at com.ibm.teamcity.tools.WASDriverLoader.run(WASDriverLoader.java:173)
: at com.ibm.teamcity.tools.WASDriverLoader.main(WASDriverLoader.java:199)
: Process exit code: 1
: Build finished

When I run the same program in a command windows in the agent's system, it yeilded the proper output and here is the output:

C:\TeamCity\.BuildServer\config\JPA FVT Run\checkout>java -cp . com.ibm.teamcity.tools.WASDriverLoader

    • isDir =true

    • isFile=false

    • exists=true

fCommitted=b:\
build level = B:\was_defects/linux/zipper/externals/installables/
B:\was_defects\linux\zipper\externals\installables

p.s. the B: drive is mapped to a network drive
anotherhost\aResource

Albert Lee.



Attachment(s):
WASDriverLoader.java
0

I do not think it is actually related to TeamCity agent. I think you should try to debug your code with help of remote debug facility. The issue can also be related to security settings of the java you are using. Try to launch your class with another java.

--
Pavel Sher

0

I switched to another JVM (Sun) and it still failed.

There is no JAVA 2 security applied to the jvm. I double checked and there is NO security manager installed.

I started the command runner with a java jvm and enabled remote debug. Launch an agent run instance and attached the jvm to an Eclipse debugger. Stepped into the File.listFiles() method, the java.io.File class calls out to a native WinNTFileSystem (implements FileSystem interface) to get a String[] of files in this folder. The javadoc indicates the listFiles() returns null if the abstract pathname is NOT a directory. The File.isDirectory() actually returns false. So it looks like it behaves consistently. Somehow the native FileSystem implementation does not recognize remote folder when it is launched fromt within SimpleRunner.

As I noted before, the same sample test program works if it is launched in a command window in the same system where the agent service is run. Both runs uses the same JVM.

I have been scratching my head on who could be the cause of this problem.

Thanks,
Albert Lee.

0

Have you tried to launch agent via agent.bat?

--
Pavel Sher

0

Please sign in to leave a comment.