团队城市构建失败不返回失败代码 [英] Team City build fail not returning fail code
问题描述
我有一个在 TeamCity 上运行 Invoke-MsBuild 的 powershell 脚本.在构建过程中,我看到了警告:无法构建"其中一个项目.然而teamcity最后说构建是成功的.如何强制 TC 以错误代码退出或至少报告构建失败.这是构建脚本的一部分.
I have a powershell script that runs Invoke-MsBuild on TeamCity. During a build I saw a "WARNING: FAILED to build" one of the projects. However teamcity at the end said the build was successful. How can I force TC to exit with an error code or at least report the build failed. Here is part of the build script.
Write-Host "Attempting to build $SolutionPath"
$buildSucceeded = Invoke-MsBuild -Path $SolutionPath -MsBuildParameters $MSBuildParams -BuildLogDirectoryPath "$BuildPath\Logs" -KeepBuildLogOnSuccessfulBuilds
推荐答案
TeamCity 不太擅长捕获和报告从 Powershell 抛出的异常.我所有的 Powershell 脚本都用类似
TeamCity isn't very good at catching and reporting exceptions thrown from Powershell. All my Powershell scripts are wrapped with something like
Try {
Write-Host "Attempting to build $SolutionPath"
$buildSucceeded = Invoke-MsBuild -Path $SolutionPath -MsBuildParameters $MSBuildParams -BuildLogDirectoryPath "$BuildPath\Logs" -KeepBuildLogOnSuccessfulBuilds
}
Catch [Exception] {
Write-Error ('Failed: ' + $_.Exception.Message)
Exit 1
}
通过退出非零来弥补这个问题.
that makes up for the problem by exiting non-zero.
我承认这很麻烦,也有些不尽人意.我怀疑使用一般的 -ErrorAction
大多数(全部?)Powershell cmdlet 支持的参数.(话虽如此,我不确定 Invoke-MsBuild -ErrorAction Stop
是否有效.)
I admit this is quite cumbersome and somewhat unsatisfactory. I suspect something may be gained by using the general -ErrorAction
parameter that most (all?) Powershell cmdlets support. (Having said that, I'm not sure Invoke-MsBuild -ErrorAction Stop
works.)
这篇关于团队城市构建失败不返回失败代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!