2
votes

When trying to create a report using 'ReportGenerator' tool as part of Azure devops YAML pipleine, below error is being thrown though i installed the tool in previous step.

- 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'.

3
Have you tried restarting the build agent service? Is your issue solved? - Cece Dong - MSFT

3 Answers

1
votes

There is a known bug when you are trying to do that on Linux machine. After report generator installation, please try to add this additional step to update the PATH:

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

So the whole solution looks like this:

- 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
1
votes

The following YAML file should do the job:

- 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"

You can also use the Azure DevOps extension:
https://marketplace.visualstudio.com/items?itemName=Palmmedia.reportgenerator

Usage:

- 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
votes

This is because you are using Self-hosted agent. After you install new software on an agent, you must restart the agent for the new capability to show up in the pool so that the build can run.

Just go to Task Manager on your agent machine and restart the build agent service.