How to you identify why a Windows service (TeamCity build agent) is hanging when running a command

teamcitytroubleshootingwindows-service

I've got a problem with a Windows service I just simply can't get to the bottom of. What I'm trying to do is execute the HP WebInspect 9.0 application from a TeamCity build agent which runs as a Windows service. The ultimate objective is to automate security scans after the application is published to the target environment.

I have a command which executes beautifully from the command window when I'm remoted into the server:

"C:\Program Files\HP\HP WebInspect\wi.exe" -u http://mysite.com -r "Vulnerability (Classic)" -y Standard -f c:\Temp\Report.pdf -gp -v

This command returns verbose output to the terminal on a regular basis (every few minutes) and eventually drops a report in PDF format after about 13 minutes (fairly consistent duration). However, once I run it from TeamCity, I can see the the command appear in the build output on the TeamCity server but absolutely nothing after that. Even after 8 hours, it just hangs and I have no idea why.

Some more info:

  1. The TeamCity build agent service is running under my identity so it should have the same rights as when I execute it manually from the command line.
  2. If I change one of the parameters to something invalid, WebInspect returns an "invalid parameter" message so I know it's definitely being called.
  3. Watching processes in the task manager, I can see WI.exe start up when I begin the build so again, it's definitely executing.
  4. I'm not getting anything in the event logs of any use.
  5. I can't find any logs from WebInspect generated as a result of using the command line (although there are logs accessible from scans executed in the GUI).
  6. There is nothing else in the WebInspect command line switches beyond the verbose output setting which would appear to provide any more information.

My suspicion is that for some reason it's sitting there waiting for input but I have no idea why. I'm making an assumption that a service running a command under my identity should behave the same as when I'm logged onto the box and executing the same command – is this assumption wrong? Is there anything else I can look at to try and get to the bottom of this?

Best Answer

As a first step I would recommend saving your long command line into a batch file (e.g. LaunchWI.cmd) and calling this batch file from the TeamCity build agent.

When you launch an app from a windows service the current working directory will be set to c:\windows\system32 - this can potentially cause some issues. Try adding

C:

CD "\Program Files\HP\HP WebInspect"

into your batch file before launching webinspect.

Related Topic