You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps管道运行Postman集合出现测试结果警告及选项卡缺失问题

问题描述
  • Azure DevOps管道执行Postman集合整体流程无报错,但发布测试结果环节收到警告:##[warning]No test result files matching **/*.xml were found
  • 管道运行完成后,测试摘要页面缺失「测试」选项卡,需要排查脚本配置遗漏。
  • 原有YAML配置如下:
pool:
  name: Azure Pipelines
  demands: npm

steps:
- task: Npm@1
  displayName: 'npm custom'
  inputs:
    command: custom
    verbose: false
    customCommand: 'install -g newman'

- task: Npm@1
  displayName: 'Install html report'
  inputs:
    command: custom
    verbose: false
    customCommand: 'install -g newman-reporter-htmlextra'

- script: |
    echo $(Build.ArtifactStagingDirectory)
    cd $(Build.ArtifactStagingDirectory)
    dir
  displayName: 'Command Line Script'

- script: |
    newman run ./PostmanCollection.json -g ./GlobalVariables.json -e ./EnvironmentVariables.json -r htmlextra --reporters cli,junit.json.htmlextra  --reporter-junit-export-junitReport.xml --reporter-htmlextra-export TestReport.html
  displayName: 'Run API Test With Report'
  continueOnError: true

- task: PublishPipelineArtifact@1
  displayName: 'Publish Pipeline Artifact'

- task: PublishTestResults@2
  displayName: 'Publish Test Results '
  inputs:
    testResultsFiles: '**/*.xml'
    mergeTestResults: true
    testRunTitle: Results
问题根因

配置存在3处核心错误,导致Junit格式的XML测试结果根本没有生成,后续发布测试结果任务扫描不到对应文件,自然无法展示「测试」选项卡:

  1. newman命令的报告器列表参数写错:--reporters后面的多个报告器需要用英文逗号分隔,原有配置写为cli,junit.json.htmlextra,把逗号错写为点,newman无法识别到junit报告器,不会生成XML格式结果。另外前面重复写了-r htmlextra(-r是--reporters的简写),属于冗余无效参数。
  2. Junit报告导出参数写错:正确格式为--reporter-junit-export <文件输出路径>,参数和路径之间需要用空格分隔,原有配置写为--reporter-junit-export-junitReport.xml,属于无效参数,newman会直接忽略,不会输出junitReport.xml文件。
  3. PublishPipelineArtifact@1任务缺失必填参数,没有指定要发布的文件路径,就算HTML报告生成成功也无法正常发布到管道制品。

额外注意:脚本中执行了cd $(Build.ArtifactStagingDirectory)切换到制品暂存目录,该目录默认为空,如果Postman集合、全局/环境变量JSON文件没有提前拷贝到该目录,newman运行时会找不到测试文件。

修正后完整YAML配置
pool:
  name: Azure Pipelines
  demands: npm

steps:
- task: Npm@1
  displayName: '安装newman'
  inputs:
    command: custom
    verbose: false
    customCommand: 'install -g newman'

- task: Npm@1
  displayName: '安装htmlextra报告插件'
  inputs:
    command: custom
    verbose: false
    customCommand: 'install -g newman-reporter-htmlextra'

- script: |
    # 拷贝测试相关文件到制品暂存目录
    cp $(Build.SourcesDirectory)/PostmanCollection.json $(Build.ArtifactStagingDirectory)/
    cp $(Build.SourcesDirectory)/GlobalVariables.json $(Build.ArtifactStagingDirectory)/
    cp $(Build.SourcesDirectory)/EnvironmentVariables.json $(Build.ArtifactStagingDirectory)/
    cd $(Build.ArtifactStagingDirectory)
    dir
  displayName: '准备测试文件'

- script: |
    newman run ./PostmanCollection.json -g ./GlobalVariables.json -e ./EnvironmentVariables.json --reporters cli,junit,htmlextra --reporter-junit-export ./junitReport.xml --reporter-htmlextra-export ./TestReport.html
  displayName: '执行API测试生成报告'
  continueOnError: true

- task: PublishPipelineArtifact@1
  displayName: '发布测试报告制品'
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)'
    artifact: 'API_Test_Report'
    publishLocation: 'Container'

- task: PublishTestResults@2
  displayName: '发布测试结果'
  inputs:
    testResultsFiles: '**/*.xml'
    mergeTestResults: true
    testRunTitle: 'Postman接口测试结果'
    searchFolder: '$(Build.ArtifactStagingDirectory)'
修正说明
  • 补全测试文件准备逻辑,提前把代码仓库里的Postman集合、变量文件拷贝到制品暂存目录,避免切换目录后找不到测试文件。
  • 修正newman运行参数:删除冗余的-r htmlextra,把报告器列表改为正确的逗号分隔格式cli,junit,htmlextra,修正Junit报告导出参数,确保XML测试结果正常生成。
  • 补全PublishPipelineArtifact@1的必填参数,指定制品发布路径和名称,确保HTML测试报告可以正常下载查看。
  • 给PublishTestResults@2增加searchFolder参数,指定扫描XML结果的目录为制品暂存目录,避免全目录扫描的性能问题,确保能准确找到生成的Junit报告。

配置修正后,管道运行时会正常生成XML测试结果,发布测试结果任务不会再报找不到文件的警告,运行完成后摘要页会自动展示「测试」选项卡,可以直接查看接口测试的通过率、失败用例详情等数据。

内容的提问来源于stack exchange,提问作者user14551704

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 15:21:17