Showing `dnu publish` exceptions in TeamCity Build Results

时光毁灭记忆、已成空白 提交于 2019-12-24 03:30:18

问题


I've spent about 3 days to setup TeamCity to build and publish asp.net-5 project. Finally I did it by using dnu publish command to publish the site. I'm using the batch file to do it with following commands

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

The questions are

  1. Is it possible to return errors/exceptions from dnu publish command to show that publishing is failed? For example, I can get an exception while doing publishing
    • The process cannot access the file..... or
    • The path length cannot be longer than 260 characters ...

BUT the TeamCity Build Result will be shown as Success, so I always need to check that it really finished without any exceptions.

  1. Is there another better way/script to publish asp.net-5 site? Maybe I'm just doing something wrong.

回答1:


This is a little late, but I have something that's been working for us. I've been using a powershell script to wrap my command line calls. Because it's PS, you can do a try/catch and then in the catch I use the ##teamcity attribute to flag the failure to team city. Also make sure you exit with a status code other than 0. Notice that I'm forcing an exit with status code 1 to indicate a failure. Finally, make sure any command line calls in your PS script are prefaced with a "&".

So for example to call DNU publish (I'm using an environment variable I set up in team city to indicate the dnx version).

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)
}


来源:https://stackoverflow.com/questions/32338218/showing-dnu-publish-exceptions-in-teamcity-build-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!