Question

I'm trying to install a service using TopShelf from CI. However whenever an exception occurs during installation, TopShelf rollsback the transaction and continues with the build process, returning a 0x0 status.

This means that as far as the CI server is concerned, the deployment was successful.

An example of the command I'm using in MSBuild is:

<Message Text ="Installing Service" />
<Exec Command=""$(MSDeployPath)" -verb:sync -source:runCommand="$(RemoteServicePath) install /instance:$(DeployEnvironment)",dontUseCommandExe=false,waitAttempts=10,waitInterval=10000 -dest:auto,computername=%(ComputerName) -verbose -retryInterval:10000 -retryAttempts:10"></Exec>

The output I receive is:

[Exec] Running a transacted installation. <br>
[Exec] <br>
[Exec] Verbose: Received response from agent (HTTP status 'OK'). <br>
[Exec] Info: <br>
[Exec] Beginning the Install phase of the installation. <br>
[Exec] <br>
[Exec] Info: Installing service Foo...<br>
[Exec] <br>
[Exec] Info: Creating EventLog source Foo in log Application...<br>
[Exec] <br>
[Exec] Info: <br>
[Exec] An exception occurred during the Install phase.<br>
[Exec] <br>
[Exec] Info: System.ComponentModel.Win32Exception: The specified service already exists<br>
[Exec] <br>
[Exec] The Rollback phase of the installation is beginning.<br>
[Exec] Restoring event log to previous state for source Foo.<br>
[Exec] <br>
[Exec] The Rollback phase completed successfully.<br>
[Exec] <br>
[Exec] The transacted install has completed.<br>

Any ideas how I can make the build fail on the exception?

Was it helpful?

Solution

The latest release of Topshelf (3.0.2) added a TopshelfExitCode, which is an enum that can be cast to an (int) and returned from Main in your console application.

If install/uninstall fails, the error code is non-zero (the enumeration has all the possible values). So now it should play nicely with batch files/builds expecting non-zero exit codes when things don't install properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top