‘reportgenerator’不被识别为内部或外部命令、可操作程序或批处理文件

问题描述 投票:0回答:3

当尝试使用“ReportGenerator”工具创建报告作为 Azure Devops YAML 管道的一部分时, 尽管我在上一步中安装了该工具,但仍抛出以下错误。

- script: dotnet tool install --global dotnet-reportgenerator-globaltool --version 4.6.1
  displayName: 'Install ReportGenerator tool'
  continueOnError: true

- script: reportgenerator "-reports:$(Agent.TempDirectory)/**/*.cobertura.xml" "-targetdir:$(Build.SourcesDirectory)/coverlet/reports" -reporttypes:Cobertura;htmlInline
  displayName: Generate code coverage report
  continueOnError: true
Error : 'reportgenerator' is not recognized as an internal or external command,
operable program or batch file.
##[error]Cmd.exe exited with code '1'.

Adding logs
Install Step:
Script contents:
dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools --version 4.6.1
========================== Starting Command Output ===========================
"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "E:\Agent_work\_temp\d9535a65-152b-4822-a4f2-7e58c11f2418.cmd""
You can invoke the tool using the following command: reportgenerator
Tool 'dotnet-reportgenerator-globaltool' (version '4.6.1') was successfully installed.
Finishing: Install ReportGenerator tool

Executing tool :
Script contents:
reportgenerator "-reports:E:\Agent_work\_temp/**/*.cobertura.xml" "-targetdir:E:\Agent_work\79\s/coverlet/reports" -reporttypes:Cobertura;htmlInline
========================== Starting Command Output ===========================
"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "E:\Agent_work\_temp\53dbc699-e878-4458-aaf2-8e69e5c4f09a.cmd""
'reportgenerator' is not recognized as an internal or external command,
operable program or batch file.
##[error]Cmd.exe exited with code '1'.
.net-core azure-devops continuous-integration yaml reportgenerator
3个回答
3
投票

当您尝试在 Linux 计算机上执行此操作时,存在 一个已知错误 。安装报告生成器后,请尝试添加此附加步骤来更新路径:

- script: echo "##vso[task.prependpath]$HOME/.dotnet/tools"

所以整个解决方案如下所示:

- task: DotNetCoreCLI@2
    displayName: Install ReportGenerator Global Tool
    inputs:
      command: custom
      custom: tool
      arguments: install dotnet-reportgenerator-globaltool -g

- script: echo "##vso[task.prependpath]$HOME/.dotnet/tools"
  displayName: 'Update PATH'

- script: reportgenerator "-reports:$(Agent.TempDirectory)/**/*.cobertura.xml" "-targetdir:$(Build.SourcesDirectory)/coverlet/reports" -reporttypes:Cobertura;htmlInline
  displayName: Generate code coverage report
  continueOnError: true

2
投票

以下 YAML 文件应该可以完成这项工作:

- script: dotnet tool install --tool-path tools dotnet-reportgenerator-globaltool --version 4.6.1
  displayName: 'Install ReportGenerator tool'
  continueOnError: true

- script: ./tools/reportgenerator "-reports:$(Agent.TempDirectory)/**/*.cobertura.xml" "-targetdir:$(Build.SourcesDirectory)/coverlet/reports" "-reporttypes:Cobertura;HtmlInline"

您还可以使用 Azure DevOps 扩展:
https://marketplace.visualstudio.com/items?itemName=Palmmedia.reportgenerator

用途:

- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
  displayName: ReportGenerator
  inputs:
    reports: '$(Agent.TempDirectory)/**/*.cobertura.xml'
    targetdir: '$(Build.SourcesDirectory)/coverlet/reports'
    reporttypes: 'Cobertura;HtmlInline'

0
投票

这是因为您使用的是自托管代理。在代理上安装新软件后,必须重新启动代理才能使新功能显示在池中,以便构建可以运行。

只需转到代理计算机上的任务管理器并重新启动构建代理服务。

© www.soinside.com 2019 - 2024. All rights reserved.