我正在尝试使用CI中的TopShelf安装服务。但是,无论何时在安装期间发生异常,TopShelf都会回滚事务并继续构建过程,返回0x0状态。
这意味着就CI服务器而言,部署成功。
我在MSBuild中使用的命令示例是:
<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>
我收到的输出是:
[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>
我是如何在异常中使构建失败的?
答案 0 :(得分:1)
最新版本的Topshelf(3.0.2)添加了一个TopshelfExitCode,这是一个可以强制转换为(int)并在控制台应用程序中从Main返回的枚举。
如果安装/卸载失败,则错误代码为非零(枚举具有所有可能的值)。所以现在它应该可以很好地处理批处理文件/构建,当事情没有正确安装时,期望非零退出代码。