在 TeamCity 中获取构建步骤退出代码
我有一个包含许多构建步骤的构建,这些步骤通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置StopOnFirstFailure=true
此外,定义构建参数< /strong> 并有条件地设置 TeamCitySetStatus。
Set StopOnFirstFailure=true
Additionally, define build parameters and conditionally set the TeamCitySetStatus.
如果您有一个单独的步骤并且每个步骤都有一个单独的构建脚本,那么在 teamcity 中这很容易做到。但是,如果您使用一个脚本来完成每一件事(构建、测试、打包和部署),并且只有一个 teamcity 步骤来调用该脚本,那么它就会变得相当困难,因为您将不得不添加大量的 try 和 catch不适用于不可捕获的错误。
我建议使用
psake
。要使用psake
,您需要有 2 个脚本。第一个是由 teamcity 运营的。在第一个脚本中,您导入 psake 模块并调用主脚本,该脚本会为您完成所有操作。如果第二个脚本在任何地方失败,它将停止该脚本(前提是您的代理有stoponfailure
powershell 策略)。第二个脚本将停止并返回到第一个脚本。但第一个脚本不会将其视为失败,并将显示构建成功。为了克服这个问题,您可以在第一个脚本中添加一段代码。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 usepsake
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 havestoponfailure
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.Powershell exit code is always 0 in teamcity build step