target using psexec runs locally but not via agent

I'm trying to debug why my nant target which uses psexec to run a process on a remote computer does not run from my build agent.

The nant target has been simplified to this

]]>
<arg line="
10.0.27.142"/>
This simply runs ping on 10.0.27.142 by logging into the default admin account. This target can be executed fine from a command line while logged into build agent's machine. C:\BuildAgent\work\b332854fbda00e52>]]>nant test
NAnt 0.86 (Build 0.86.3152.0; nightly; 18.08.2008)
Copyright (C) 2001-2008 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/BuildAgent/work/b332854fbda00e52/deploy.build
Target framework: Microsoft .NET Framework 2.0
Target(s) specified: test

Target framework changed to "Microsoft .NET Framework 3.5".

test:


PsExec v1.94 - Execute processes remotely
Copyright (C) 2001-2008 Mark Russinovich
Sysinternals - www.sysinternals.com



Pinging 127.0.0.1 with 32 bytes of data:



Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

etc and the test runs fine. I am logged into the build agent's machine with the same user profile that is used to run the agent's Window Service.

When I execute the same exact static target from teamcity and instruct the agent to run the task, the psexec process hangs and the project does not complete. The user profiles in both cases are the same. The build script itself is the same in both cases. The executables being used are the same. Yet it will not execute properly from the Windows Service

The build log just says

: exec (running for 6m)
: Starting 'C:\BuildAgent\work\b332854fbda00e52\psexec (-accepteula
10.47.27.142 -u administrator -p TANDBERG ping 127.0.0.1)' in 'C:\BuildAgent\work\b332854fbda00e52'
:
: PsExec v1.94 - Execute processes remotely
: Copyright (C) 2001-2008 Mark Russinovich
: Sysinternals - www.sysinternals.com
:
:
:

Looking at the thread dump.. it simply says it ran the command
"C:\BuildAgent\work\b332854fbda00e52\psexec" -accepteula
10.47.27.142 -u administrator -p TANDBERG ping 127.0.0.1

which is perfectly correct. Any ideas on where to go from here?

Using TeamCity 3.1 build 6760 on Windows Server, with the agent running on Windows Server 2003 with the agent logging in as a domain user account.

Edited by: SKapinos on Sep 15, 2008 2:45 AM

6 comments
Comment actions Permalink

Issues with psexec seem to be related to the process output capturing performed by TeamCity (Java) and some non-standard way of outputting used by psexec.

Here is a related thread:
http://www.intellij.net/forums/thread.jspa?messageID=5221186&#5221186

You can try the output redirection trick noted in that thread.

To isolate running as service issues you can try to launch agent in console mode (by "agent.bat start").

0
Comment actions Permalink

The people in that thread are getting error code results... my case it just sits deaf and dumb.

I tried your > null suggestion, but can't seem to get a nant syntax that will take. If I add it in as another arg line, psexec complains of bad parameter. How can I add it to the command line without actually passing it as a parameter to psexec?

Using this
]]>
<arg line="
10.0.27.142"/>
]]>

Results in

test4:


PsExec v1.94 - Execute processes remotely
Copyright (C) 2001-2008 Mark Russinovich
Sysinternals - www.sysinternals.com

Bad parameter >.

Well... psexec seems to have a dirty history with no real solutions - but my alternatives seem to have the same issues. I even tried burying psexec in a batch file and simply calling the batch file in the exec statement without any luck.

Thanks for the agent.bat tip - it doesn't seem to have an impact on running as a service or not. Same issue in both cases.

Here's the batch file example

test2.bat is simply
psexec.exe -accepteula
10.0.27.142 -u administrator -p TANDBERG ping 127.0.0.1 > nul
if "%ERRORLEVEL%"=="1" echo BORK

The nant task is
]]>

When executed via the agent, the build log simply shows this forever

: Build sequence for target `test3' is test3
: Complete build sequence is test3, all, deployUninstall, deployInstall, waitForCleanServer, waitForTMSServer, deployReboot, mapDelete, mapRemoteDir, resetDeployDir, deployFiles, test, test2, test4
: exec (running for 3m:42s)
: Starting 'C:\BuildAgent\work\b332854fbda00e52\test2.bat ()' in 'C:\BuildAgent\work\b332854fbda00e52'
:
: C:\BuildAgent\work\b332854fbda00e52>psexec.exe -accepteula
10.0.27.142 -u administrator -p TANDBERG ping 127.0.0.1 1>nul
:
: PsExec v1.94 - Execute processes remotely
: Copyright (C) 2001-2008 Mark Russinovich
: Sysinternals - www.sysinternals.com
:

But here's another example, not using psexec. As an alternative, I tried to use the command line tool for WMI supplied with windows, wmic.exe. It demostrates the exact same behavior.. works fine via command line nant execution, hangs via the agent.

The equivalent 'simple' test is
]]>

This works fine if I call nant locally - but hangs forever when called via the agent.

0
Comment actions Permalink

I believe exit code in the other thread was produced after stopping a build form the web UI. At least I experienced such behavior in my tries with psexec (it hangs and exits with -1 on build canceling).

I used command line runner and the "> null" trick helped in my case.

From the psexec forum it seems such issues are rather common, so I tend to think this is more related to psexec then the way TeamCity launches the process. Since it's the utility that hangs, I doubt we will be able to resolve the issue at our side. However, if you get any additional details on the issue, please let us know.

0
Comment actions Permalink

But what about the example above with wmic.exe? That's a totally seperate utility and experiences similar results. You should be able to duplicate the same scenario using my example above.. its generic and supported between any two modern windows machines baring firewall issues.

Can you give an example of how you used the command line runner?

I've tried

]]>
<exec program="psexec" basedir="." workingdir="." commandline="-accepteula
10.0.27.142 -u administrator -p TANDBERG ping 127.0.0.1 > nul"/>
and ]]>
<arg line="
10.0.27.142"/>
without luck I finally got nant to take it if I did it this way ]]>
<exec program="cmd.exe" workingdir="." commandline="/c psexec.exe -accepteula
10.47.27.142 -u administrator -p TANDBERG ping 127.0.0.1 > nul"/>
</target>

But while that ran in nant via console - it still failed identically when called via agent.

0
Comment actions Permalink

I am experiencing something similar with TeamCity NAnt runner and wmic.exe. I use NAnt to run ]]> task to compile a C# program that internally calls wmic.exe. Everything is peachy on the command line and hangs when it runs on the agent. Are you trying to access a mapped drive in your command by any chance? There is an issue with Windows service not able to access mapped drives. See the discussion here for details on that.

Yegor:
Would you be able to have your team put their JetBrains(!) together and to see if you can reproduce the same issue and maybe come up with a workaround? I've been looking for a workaround for a few days now, and I'm sure that several of us would appreciate any ideas (except, perhaps, using agent.bat).

Thanks,
Oleg.

Edited by: Oleg Gerovich on Oct 29, 2008 4:08 PM

Edited by: Oleg Gerovich on Oct 29, 2008 4:23 PM

0
Comment actions Permalink

My solution was to use WMI in a visual basic script, called from cscript.exe to make it a dos/console app.

I could not make psexec or wmic.exe work from within the agent under any user.

0

Please sign in to leave a comment.