I have a step in TeamCity where it tests a deploy first before executing the next step(which has a "Execute:if all previous steps finished successfully" option selected). I used .deploy.cmd script and passed /T switch to execute in test mode. The process returns with code 0 but the test deploy returns and error code.

How do I get it to fail and not go to next step? (below is the snapshot of the error)

Thanks,

Error Snapshot

1

There are 1 best solutions below

1
On

You can use Runner type PowerShell for call your cmd script. When you use PowerShell you can use try-catch structure and return error code > 0 when your code get error.

E.g.:

$result = $null
try
{
    $result = &("C:\Users\guest\deploy.cmd") %TestArg%
}
catch
{
    $errorMessage = $_.Exception.Message
    Write-Error "Error on deploy: $errorMessage"
    exit 1
}
echo $result

Where, %TestArg% is your Configuration Parameter, and equals /T or nothing. If your script returns some result, you can parse it and return error code manually

if($result.ToLower().Contains("error"))
{
    Write-Error "Deploy operation result contains error(s)"
    exit 1
}

Note: As it seemed to me the parameter Format stderr output as is responsible only for the color of the display errors in build log. I use this solution for deploy database via SSDT (SqlPackage.exe), because it not abort building and next steps even in the case of an error