Showing `dnu publish` exceptions in TeamCity Build Results
Asked Answered
A

1

2

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.
Amboise answered 1/9, 2015 at 18:7 Comment(4)
if dnu publish fails, I would imagine it should return a non-success exit code...are you seeing it not doing?Prothorax
@Prothorax Challa, I tried to catch %ERRORLEVEL% but without successAmboise
I'm not familiar with dnu publish but TeamCity can receive messages from build scripts and you can tell it that the build step has failed. Have a look at the buildStatus messages.Bluefarb
@Nanhydrin, the problem here is that to send a message to the TeamCity about error/exception I have to somehow to catch the error from dnu publish which I'm trying to achieve but without success.Amboise
S
0

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)
}
Scalable answered 14/9, 2015 at 21:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.