问题
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
- 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.
- 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