I want to generate a single coverage report for my C# project based on this tutorial
When running the following Powershell script locally everything works as expected
dotnet test --collect:"XPlat Code Coverage";
dotnet tool install -g dotnet-reportgenerator-globaltool;
reportgenerator -reports:'**/coverage.cobertura.xml' -targetdir:'CoverageReports' -reporttypes:'Cobertura';
but when starting a Gitlab CI pipeline with the following configuration
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- build
- unit-tests
build:
stage: build
script:
- dotnet build --output build
artifacts:
paths:
- build
unit-tests:
stage: unit-tests
script:
- |-
dotnet test --no-build --output build --collect:"XPlat Code Coverage";
dotnet tool install -g dotnet-reportgenerator-globaltool;
reportgenerator -reports:'**/coverage.cobertura.xml' -targetdir:'CoverageReports' -reporttypes:'Cobertura';
artifacts:
reports:
cobertura: CoverageReports/Cobertura.xml
dependencies:
- build
I get the following error
The report file pattern ‘**/coverage.cobertura.xml’ is invalid. No matching files found.
Does someone know how to fix it? Do I have to specify a target directory?
Here is a repository showing what I have so far. Unfortunately I can’t test the CI on the public Gitlab (I’m working on a self hosted one)
The additional powershell file works as expected when running it locally.
When running a pipeline without the build stage
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- unit-tests
unit-tests:
stage: unit-tests
script:
- |-
dotnet test --collect:"XPlat Code Coverage";
dotnet tool install -g dotnet-reportgenerator-globaltool;
reportgenerator -reports:'**/coverage.cobertura.xml' -targetdir:'CoverageReports' -reporttypes:'Cobertura';
artifacts:
reports:
cobertura: CoverageReports/Cobertura.xml
everything works as expected. So it seems the reportgenerator needs to know about the build output (the artifact from the build stage)
Paths I tried for the -reports flag but didn’t work
-
'**/coverage.cobertura.xml' -
'build/**/coverage.cobertura.xml' -
'./**/coverage.cobertura.xml' -
'../**/coverage.cobertura.xml' -
'*/**/coverage.cobertura.xml' -
'$CI_PROJECT_DIR/**/coverage.cobertura.xml'
when running ls; and ls build; (the artifact) before running the report generator command the folder structure looks as expected
For ls;
For ls build;
but I do not need the build artifact because the coverage.cobertura.xml files shouldn’t exist there. They should be located at
-
........\temp-20210730\TestProject1\TestResults\380e65f7-48d5-468f-9cbc-550c8e0aeda8\coverage.cobertura.xml -
........\temp-20210730\TestProject2\TestResults\c96c55f7-40d3-483e-a136-573615e3a9c3\coverage.cobertura.xml


