在TeamCity Build Results中显示`dnu publish`异常

时间:2015-09-01 18:07:20

标签: c# teamcity asp.net-core dnu

我花了大约3天的时间来设置TeamCity来构建和发布asp.net-5项目。最后,我使用dnu publish命令发布了该网站。我正在使用批处理文件来执行以下命令

// stops the apppool for 'samplesite' overvise it returns exception
// The process cannot access the file '...' because it is being used by another process
call "%windir%\system32\inetsrv\appcmd" stop apppool "samplesite"

// publish the site to the --out dir
call "C:\Users\Administrator\.dnx\runtimes\dnx-coreclr-win-x86.1.0.0-beta6\bin\dnu" publish --out "F:\Sites\samplesite" --runtime dnx-clr-win-x86.1.0.0-beta6

// copies the 'prod' config.json
copy "..\..\build\configuration\samplesite\config.json" "F:\Sites\samplesite\approot\src\samplesite\config.json" /Y

// copies the 'prod' web.config
copy "..\..\build\configuration\samplesite\web.config" "F:\Sites\samplesite\wwwroot\web.config" /Y

// starts the  apppool for 'samplesite'
call "%windir%\system32\inetsrv\appcmd" start apppool "samplesite"

问题

  1. 是否可以从dnu publish命令返回错误/异常以显示发布失败? 例如,我可以在发布时获得异常
    • 该过程无法访问文件.....或
    • 路径长度不能超过260个字符......
  2. 但是TeamCity构建结果将显示为Success,因此我总是需要检查它是否完全没有任何例外。

    1. 是否有另一种更好的方式/脚本来发布asp.net-5网站?也许我只是做错了什么。

1 个答案:

答案 0 :(得分:0)

这有点晚了,但我有一些对我们有用的东西。我一直在使用powershell脚本来包装我的命令行调用。因为它是PS,你可以做一个try / catch然后在catch中我使用## teamcity属性来标记团队城市的失败。另外,请确保使用0以外的状态代码退出。请注意,我强制退出状态代码为1表示失败。最后,确保PS脚本中的任何命令行调用都以“&”开头。

例如,调用DNU发布(我正在使用我在团队城市中设置的环境变量来指示dnx版本)。

try
{
    & dnvm use $env:dnxversion -arch x64
    & dnu publish --no-source --configuration Release --runtime dnx-clr-win-x64.$env:dnxversion 
}
catch
{
    Write-Error $_
    ##teamcity[buildStatus status='FAILURE']
    [System.Environment]::Exit(1)
}