2012-08-08 61 views
3

我正嘗試從CI安裝使用TopShelf的服務。但是,無論何時在安裝期間發生異常,TopShelf回滾事務並繼續構建過程,返回0x0狀態。TopShelf MSDeploy在出錯時安裝退出代碼

這意味着就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> 

任何想法如何,我可以使異常在構建失敗?

回答

1

最新版本的Topshelf(3.0.2)添加了一個TopshelfExitCode,它是一個枚舉,可以在控制檯應用程序中將其轉換爲(int)並從Main返回。

如果安裝/卸載失敗,則錯誤代碼爲非零(枚舉具有所有可能的值)。所以,現在它應該可以很好地與批處理文件/構建,當事情不正確安裝時期望非零退出代碼。

+0

你有沒有使用退出代碼的例子? – dhaken 2012-10-15 15:13:09

+1

'ur_service.exe安裝'然後'如果錯誤級別0轉到開心'和'如果錯誤級別1轉到bad_time' – 2012-10-19 03:16:59

+0

我有從主返回標準的int代碼還是一個特殊的TopShelf類型? – dhaken 2012-10-23 13:00:35