提问者:小点点

在TeamCity构建结果中显示“dnu发布”异常


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

// 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"

这些问题是

  • 是否可以从dnu publish命令返回错误/异常以显示发布失败?例如,我可以在发布时得到一个异常<ul>
  • 进程无法访问文件。。。。。或
  • 路径长度不能超过260个字符

但是 TeamCity 构建结果将显示为“成功”,因此我始终需要检查它是否真的完成,没有任何异常。


共1个答案

匿名用户

这有点晚了,但我有一些对我们有用的东西。我一直在使用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)
}