在 Azure Devops 中发布测试结果任务

时间:2021-03-30 17:41:56

标签: maven junit azure-devops azure-pipelines azure-pipelines-tasks

我在 TFS/AZureDevopsServer-2019 中运行我的构建和发布管道,下面是 azure-pipeline.yml 中使用的 YAML

管道运行时不会生成分析

构建管道 enter image description here

如何根据“https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-test-results?view=azure-devops&tabs=trx%2Cyaml”,我在我的管道中添加了以下任务

- task: Maven@3
  inputs:
    mavenPomFile: '$(System.DefaultWorkingDirectory)/maven/pom.xml'
    goals: package
    mavenAuthenticateFeed: true
    sonarQubeRunAnalysis: true
    publishJUnitResults: true    
    sqMavenPluginVersionChoice: 'latest'

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'JUnit' 
    searchFolder: '$(System.DefaultWorkingDirectory)'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    codeCoverageToolOption: JaCoCo

流水线结果

2021-03-30T17:11:52.9179560Z ##[warning]No test result files matching **/TEST-*.xml were found.

enter image description here

2 个答案:

答案 0 :(得分:0)

错误消息表明没有与 **/TEST-*.xml 匹配的测试结果文件。您需要检查您的管道中是否有测试任务,并在运行测试任务后查看日志,以检查是否已生成测试文件。

另外,默认选项使用JUnit格式发布测试结果。 **/TEST-*.xml 在所有子目录中搜索名称以 TEST- 开头的所有 XML 文件。如果使用 VSTest 作为 testRunnertestResultsFiles 选项应更改为 **/TEST-*.trx

答案 1 :(得分:0)

如果有人使用部署在 Windows 机器上的代理,这里有一个提示。我建议不要为测试结果路径指定 $(System.DefaultWorkingDirectory)。测试运行器创建相对于当前工作目录的“测试结果”文件。例如,如果您正在运行junit,那么您可以指定--junit-directory /reports,代理会在当前工作目录下创建一个/reports 文件夹,.xml 文件将放置在/reports 下。相反,指定 $(System.DefaultWorkingDirectory)/reports 会产生一些不良结果。

相关问题