Azure DevOps 发布 - 如何在特定虚拟机上执行测试阶段?

Azure DevOps Releases - How to carry out a Test Stage at a specific virtual machine?

Azure => Pipelines 之后,我最终得到了两个已发布的工件:一个包含 .NET Core 控制台应用程序 (myDrop),另一个包含相应的测试库(使用 xUnit 编写)(myTestDrop).然后我继续 Azure => Releases 创建一个新的发布管道,如下所示:

我有一个 Windows 虚拟机 (VM),它已经安装了所有必要的库,例如.NET 内核;我想在那台机器上执行集成测试(上面的 2nd Stage)。具体来说,

  1. myDropmyTestDrop 复制到该 VM。
  2. 设置一些环境变量:比方说 myDrop 中的 MyConsole.exe 的路径。
  3. 然后 运行 集成测试:dotnet vstest "MyConsole.Tests.dll" --logger:trx --ResultsDirectory:"c:/Somewhere" /TestCaseFilter:"Category=IntegrationTest"
  4. 如果测试成功,dotnet.exe的返回码为0(否则为1)。
  5. 第三阶段只有 运行 秒,以防第二阶段成功。
  6. 应该有一种方法可以读取从上面的集成测试生成的 *.trx,特别是在有一些测试失败的情况下。

我在 Azure DevOps 方面的经验有限。我四处搜索,但大多数 Azure 发布示例都涉及 Web 应用程序(IIS,SQL...),而不是在特定 VM 上进行测试的普通控制台应用程序。鉴于上述情况,请随意提出其他替代方案或最佳做法。

如有任何建议,我们将不胜感激。

How to carry out a Test Stage at a specific virtual machine?

您可以在该机器上安装和使用 self-hosted 代理。请参考this document to install Self-hosted Windows agents. You need to add an agent job to the release pipeline first. Then, choose the agent pool with self-hosted agent installed.

Copy both myDrop and myTestDrop to that VM.

由于您的代理安装在 VM 上,它会自动将工件下载到其本地文件夹。

The 3rd Stage only runs in case the 2nd Stage is successful.

您可以 select 在 pre-deployment 条件下触发“After Stage”。例如,如果屏幕截图中的测试阶段失败,则部署阶段将不会部署。

There should be a way to read *.trx generated from the Integration Test above, especially in case there are some test failures.

您可以在发布结果页面的“测试”选项卡中查看测试结果。您也可以在此页面上下载 *.trx 文件。