PsExec hangs with TC 5.1

I am trying to deploy an MSI file to another server from one of my TeamCity agents, I found info about doing this using PsExec, it works fine when running it from the command line but when I set up a build configuration to run the same command (via an MSBuild script)  it hangs. I found other posts saying that this is a known issue with PsExec, I tried some of the remedies (>NUL) but to no avail and at some point I stumbled upon this post. It says in the Epilogue at the bottom of the page that:
"Pavel Sher, presumably from JetBrains, contacted me via Twitter and suggested that I try the latest TeamCity EAP. Pavel tells me that PsExec is working now with this version (would be a 5.0 EAP). Though I am not in a position to go upgrading TeamCity right now, I thought I should include this bit of info, in case someone reading this is."

Is this true? I have tried this on v5.1 but it doesn't seem to be working.

6 comments

Alex,

Do you use MSBuild runner in TeamCity to run MSBuild that executes PsExec? How do you start PsExec in the script?
Does it work if you run the same MSBuild script in a console using the same user account that TeamCity agent runs under?
If you TeamCity agent is run as a service, could you try to stop the service and run it from console (using bin/agent.bat start)?

0

Yes, I was trying using PSExec from MSBuild, infact it hangs even outside TeamCity.

I did try using RemCom instaed but with no success. I will now try using TeamCity's command line runner with a batch file.

0

I moved my psexec into a batch file, this runs fine from the command prompt using the same account running the agent service but when I try running the same batch file using the command line runner psexec hangs.

I haven't tried starting team city from the console rather than as a service yet, I'll do that next.

0

I believe the issue is caused by psexec that expects to read something from inputstream.  
To make it work, you may wrap it with simplies proceess that will close input stream at the beginning.
That was hte fix that we applied in TeamCity.

0

I was having the same problem with TeamCity executing PsExec.  I eventually figured it out with the "-i" command switch.  PsExec was working just fine via a MsBuild task, via a .Net wrapper and via straight command prompt usage, but TeamCity would just hang on the execution.  It seems that Java is expecting some response on standard in, when it invokes the psexec exe.  On the remote server I would see the psexecsvc process fire up and register in the services console appropriately, but then it would stop. After reading many posts such as this one, and struggling for far longer than I would care to admit, I eventually tried -i option, despite not needing this in any other execution scenario outside of TeamCity.  The psexec documentation indicates that -i will "Run the program so that it interacts with the desktop of the specified  session on the remote system. If no session is specified the process  runs in the console session." It is still unclear to me why this makes all the difference for TeamCity.

My final solution then is that I have a Command Line build step, using Custom Script to execute: psexec -i \\ServerName "C:\folder\file.bat"

Other quirks that I ran into included:

  1. Where to add psexec so that the system was aware of it. Answer: System32 and SysWow64 should cover it.
  2. The accepteula issue was early on, you only need to agree once, but if you leave the \accepteula switch in the script, that would cover your basis.
0

Hello,

There were an issue in the way TeamCity stats the process. TeamCity started processes has openned stdin stream. psexec.exe attemts to read from the stream.
The workaround is to start PSExec in the way stdin is defenitely closed.

Please see
http://youtrack.jetbrains.com/issue/TW-6021

0

Please sign in to leave a comment.