Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I parse the output of msdeploy and fail a TeamCity build if there are errors?

I'm using msdeploy.exe run from TeamCity for deploying ASP.Net projects to staging servers but if suffers severely from always returning a 0 status on exit, even when it raises several errors. This means that a bad deploy does not fail and all looks OK.

So I need to parse the output and have that raise an error, is there an easy way to do this? Alternatively, is there a hard way to do this?

You can see from the TeamCity build log below what is going on (errors, but carries on due to 0 exit status).

[17:32:31]: Skip copying Global.asax to  obj\Debug\Package\PackageTmp\Global.asax, File  obj\Debug\Package\PackageTmp\Global.asax is up to date
[17:32:31]: C:\Program  Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1845,5):  error : Copying file Web.Debug.config to  obj\Debug\Package\PackageTmp\Web.Debug.config failed. Could not find  file 'Web.Debug.config'.  [C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj]
[17:32:31]: Done Building Project  "C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj" (Package  target(s)) -- FAILED.
[17:32:31]: Build FAILED.
[17:32:31]: "C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj" (Package  target) (1) ->
[17:32:31]: (ValidateGlobalPackageSetting target)  ->
[17:32:31]: C:\Program  Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(817,5):  error : '..\Package\WebApp.zip' exists as a file. You can't package as  an archive directory to be the same path as an existing file. Please  delete the file before packaging. Alternative,you can call msbuild with  /t:CleanWebsitesPackage target to remove it.  [C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj]
[17:32:31]: "C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj" (Package  target) (1) ->
[17:32:31]: (CopyAllFilesToSingleFolderForPackage  target) ->
[17:32:31]: C:\Program  Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1845,5):  error : Copying file Web.Debug.config to  obj\Debug\Package\PackageTmp\Web.Debug.config failed. Could not find  file 'Web.Debug.config'.  [C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj]
[17:32:31]: 0 Warning(s)
[17:32:31]: 2 Error(s)
[17:32:31]: Time Elapsed 00:00:00.87
[17:32:31]: C:\BuildAgent\work\f3548ee02a6397b9>"C:\Program Files\IIS\Microsoft  Web Deploy"\msdeploy.exe -verb:sync -source:Package=Package\WebApp.zip  -dest:auto -setParam:"IIS Web Application Name"=MyWebName
[17:32:32]: Info: Updating setAcl (MyWebName).
[17:32:32]: Info: Updating setAcl (MyWebName).
[17:32:32]: Info: Updating setAcl  (MyWebName/App_Data).
[17:32:32]: Total changes: 3 (0 added, 0 deleted,  3 updated, 0 parameters changed, 0 bytes copied)
[17:32:32]: Process exited with code 0
[17:32:32]: Build finished
like image 640
Ryan O'Neill Avatar asked Feb 22 '10 20:02

Ryan O'Neill


2 Answers

TeamCity 7 has a Build Failures feature:

  • Edit Settings on your build configuration
  • Go to the Build Failure Conditions tab (number 4)
  • Click 'Add build failure condition'
  • Select the 'Fail build on specific text in build log' type
  • I used the string "EXEC : error count:" to catch MSDeploy errors, it works well
  • The Test button opens a handy dialog where you can test your failure condition on a previous build log that you know should have failed
  • Save

In my configuration I'm invoking msdeploy.exe directly from MSBuild, I think that's why my error text is different to yours.

Pretty cool, loving JetBrains for this.

like image 80
Andrew Myhre Avatar answered Oct 23 '22 12:10

Andrew Myhre


Here is an approach I used to catpure build failures from MSDeploy when I ran a Nant script for deployment remotely. It is not an identical scenerio but should give you a concept to go from. Basically you can run this from a shell you need a scripting language like powershell to capture the output and than post processes the plain text coming back from msdeploy. I rasied this issue with the MSDeploy team and let them know this was a pain to deal with.

http://www.lostechies.com/blogs/hex/archive/2009/12/29/update-on-using-msdeploy-for-remote-deployments.aspx

like image 22
Eric Hexter Avatar answered Oct 23 '22 11:10

Eric Hexter