У меня Powershell скрипта следующегоПочему мои коды выхода из командной строки всегда «0»?
##teamcity[progressMessage 'Beginning build']
# If the build computer is not running the appropriate version of .NET, then the build will not run. Throw an error immediately.
if((ls "$env:windir\Microsoft.NET\Framework\v4.0*") -eq $null) {
throw "This project requires .NET 4.0 to compile. Unfortunatly .NET 4.0 doesn't appear to be installed on this machine."
##teamcity[buildStatus status='FAILURE' ]
}
##teamcity[progressMessage 'Setting up variables']
# Set up varriables for build script
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
$v4_net_version = (ls "$env:windir\Microsoft.NET\Framework\v4.0*").Name
$nl = [Environment]::NewLine
Copy-Item -LiteralPath "$directorypath\packages\NUnit.2.6.2\lib\nunit.framework.dll" "$directorypath\Pandell.Tests\bin\debug" -Force
##teamcity[progressMessage 'Using msbuild.exe to build the project']
# Build the project using msbuild.exe.
# note, we've already determined that .NET is already installed on this computer.
cmd /c C:\Windows\Microsoft.NET\Framework\$v4_net_version\msbuild.exe "$directorypath\Pandell.sln" /p:Configuration=Release
cmd /c C:\Windows\Microsoft.NET\Framework\$v4_net_version\msbuild.exe "$directorypath\Pandell.sln" /p:Configuration=Debug
# Break if the build throws an error.
if(! $?) {
throw "Fatal error, project build failed"
##teamcity[buildStatus status='FAILURE' ]
}
##teamcity[progressMessage 'Build Passed']
# Good, the build passed
Write-Host "$nl project build passed." -ForegroundColor Green
##teamcity[progressMessage 'running tests']
# Run the tests.
cmd /c $directorypath\build_tools\nunit\nunit-console.exe $directorypath\Pandell.Tests\bin\debug\Pandell.Tests.dll
# Break if the tests throw an error.
if(! $?) {
throw "Test run failed."
##teamcity[buildStatus status='FAILURE' ]
}
##teamcity[progressMessage 'Tests passed']
Из того, что я ведущий верить, an uncaught Throw
приведет к выходной коде 1
, но, к сожалению, TeamCity говорит иначе.
[19:32:20]Test run failed.
[19:32:20]At C:\BuildAgent\work\e903de7564e599c8\build.ps1:44 char:2
[19:32:20]+ throw "Test run failed."
[19:32:20]+ ~~~~~~~~~~~~~~~~~~~~~~~~
[19:32:20] + CategoryInfo : OperationStopped: (Test run failed.:String) [],
[19:32:20] RuntimeException
[19:32:20] + FullyQualifiedErrorId : Test run failed.
[19:32:20]
[19:32:20]Process exited with code 0
[19:32:20]Publishing internal artifacts
[19:32:20][Publishing internal artifacts] Sending build.finish.properties.gz file
[19:32:20]Build finished
Это может быть также важно отметить, что мой Execution Mode
установлен в Execute .ps1 script with "-File" arguement
.
Я попытался изменить его на Put script into PowerShell stdin with "-Command -" arguements
, но затем он не смог с кодом выхода 1
даже с прохождением тестов. Я уверен, что запуск его как -File
будет правильным.
Если я открываю скрипт, расположенный на C:\BuildAgent\work\e903de7564e599c8\build.ps1
и запустить его вручную в CMD, он делает то же самое ... IE: Неисправные тесты потерпеть неудачу, и %errorlevel%
еще 0
.
YET, если я запустил его в PowerShell и позвонил $LASTEXITCODE
, он каждый раз возвращает правильный код.
Я даже попытался добавить '[Environment] :: Exit (1)' сразу после каждого 'throw', но он все равно не работает. –
Любой код после 'throw' не выполняется. –
Если вы измените уровень ошибок для шага сборки с «предупреждения» на «ошибка», это имеет значение? – devlord