【问题标题】:How do I have a meaningful error message from powershell script running in TeamCity build?如何从 TeamCity 构建中运行的 powershell 脚本获得有意义的错误消息?
【发布时间】:2019-02-09 12:27:31
【问题描述】:

我有一个 TeamCity 构建,其中一个步骤是调用 .proj 文件的 MSBuild:

Runner type: MSBuild
Build file path: TestProject.proj
Targets: Test

在 .proj 我有目标:

<Target Name="DeployTestService">
    <Message Text="Deploying test service" />
    <Exec Command="powershell -Command &quot;&amp; { myUsefulPsScript.ps }&quot;" />
</Target>

<Target Name="Test">
   // other stuff, then
   <CallTarget Targets="DeployTestService" />
</Target>

它在大多数情况下都很好用。然而,如果 powershell 脚本失败(抛出未处理的异常,我可以在完整日志中看到它的文本)并以非零代码退出,我会在 Teamcity 构建结果中看到以下内容:

 Tests passed: (some number); exit code 1

构建树只是说:

Build failure condition (1)
 Process exited with code 1   
   [Time]Process exited with code 1

在我获得完整的日志之前,我真的不知道哪一步失败了以及究竟是如何失败的。这不是要解决最初的问题,而是要更快地找到错误的步骤。

有没有办法让 Teamcity 说出类似“步骤 N 中的跑步者失败并出现此错误消息 [我在完整日志中看到的消息]”之类的内容?

【问题讨论】:

    标签: powershell error-handling build continuous-integration teamcity


    【解决方案1】:

    您需要使用Teamcity output format。例如,每次新测试开始时,打印:

    ##teamcity[testStarted name='foo|'s test']
    

    这样,Teamcity 将知道应用程序崩溃前的最后一步或最后一次测试是什么,并且能够相应地格式化输出。

    【讨论】:

      猜你喜欢
      • 2015-03-17
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 2011-02-08
      • 1970-01-01
      • 2022-06-15
      • 2019-01-08
      • 2018-06-09
      相关资源
      最近更新 更多