在 TeamCity 中获取构建步骤退出代码

发布于 2025-01-06 17:44:40 字数 183 浏览 0 评论 0原文

我有一个包含许多构建步骤的构建,这些步骤通过 MSBuild 脚本使用 msdeploy 编译、运行测试和打包应用程序。 目前,如果我的任何测试失败,仍然会构建包,但是我希望构建在失败点停止,或者能够将一个变量传递到 MSBuild 脚本中,该变量是测试的退出代码/compile 阶段,并根据该变量的值创建包。 目前,我无法找到包含此信息的任何变量。

I have a build with a number of build steps that compile, run tests and package the application using msdeploy via an MSBuild script.
Currently, if any of my tests fail, the package still gets built, however I would want the build to either stop at the point of failure, or to be able to pass a variable into the MSBuild script that is the exit code of the test/compile stage, and create the package based on the value of that variable.
Currently, I haven't been able to find any variables that contain this information..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲性难收 2025-01-13 17:44:41

设置StopOnFirstFailure=true

如果为 true,则当其中一个项目构建失败时,不再有项目
即将建成。

此外,定义构建参数< /strong> 并有条件地设置 TeamCitySetStatus

Set StopOnFirstFailure=true

If true, when one of the projects fails to build, no more projects
will be built.

Additionally, define build parameters and conditionally set the TeamCitySetStatus.

秋心╮凉 2025-01-13 17:44:41

如果您有一个单独的步骤并且每个步骤都有一个单独的构建脚本,那么在 teamcity 中这很容易做到。但是,如果您使用一个脚本来完成每一件事(构建、测试、打包和部署),并且只有一个 teamcity 步骤来调用该脚本,那么它就会变得相当困难,因为您将不得不添加大量的 try 和 catch不适用于不可捕获的错误。

我建议使用psake。要使用 psake,您需要有 2 个脚本。第一个是由 teamcity 运营的。在第一个脚本中,您导入 psake 模块并调用主脚本,该脚本会为您完成所有操作。如果第二个脚本在任何地方失败,它将停止该脚本(前提是您的代理有 stoponfailure powershell 策略)。第二个脚本将停止并返回到第一个脚本。但第一个脚本不会将其视为失败,并将显示构建成功。为了克服这个问题,您可以在第一个脚本中添加一段代码。

Import-Module .\psake\psake.psm1

Invoke-Psake .\build-steps.ps1 @args

if($psake.build_success -eq $false){
    write-host "There was an error running psake script"
    exit 1
}
Remove-Module psake

teamcity 中的 Powershell 退出代码始终为 0构建步骤

This is easy to do in teamcity if you have a separate step and a separate build script for each and every step. But if you are using one single script to do each and every thing (build, tests, package and deploy) and only one teamcity step to call the script then it becomes quite difficult as you will have to add a lots of try and catch which will not work on non catch able errors.

I suggest to use psake. To use psake you will need to have 2 scripts. The first one is the one which is ran by teamcity. In the first script you import psake module and call the main script which does everything for you. If the second script fails anywhere it's gonna stop the script (provided you have stoponfailure powershell policy on your agents). The second script will stop and will return to the first script. But the first script will not consider it as failure and will show the build as success. To overcome this you add a piece of code in your first script.

Import-Module .\psake\psake.psm1

Invoke-Psake .\build-steps.ps1 @args

if($psake.build_success -eq $false){
    write-host "There was an error running psake script"
    exit 1
}
Remove-Module psake

Powershell exit code is always 0 in teamcity build step

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文