How to fix this pipeline error in Exercise - Perform code coverage testing

Hassaan Faruq 80 Reputation points
2024-11-25T04:30:02.2733333+00:00

User's image

I followed these instructions and reached all the way to the end but then the pipeline failed.

My azure-pipeline.yml file looks like this.

trigger:
- '*'

pool:
  vmImage: 'ubuntu-20.04'
  demands:
  - npm

variables:
  buildConfiguration: 'Release'
  wwwrootDir: 'Tailspin.SpaceGame.Web/wwwroot'
  dotnetSdkVersion: '6.x'

steps:
- task: UseDotNet@2
  displayName: 'Use .NET SDK $(dotnetSdkVersion)'
  inputs:
    version: '$(dotnetSdkVersion)'

- task: Npm@1
  displayName: 'Run npm install'
  inputs:
    verbose: false

- script: './node_modules/.bin/node-sass $(wwwrootDir) --output $(wwwrootDir)'
  displayName: 'Compile Sass assets'

- task: gulp@1
  displayName: 'Run gulp tasks'

- script: 'echo "$(Build.DefinitionName), $(Build.BuildId), $(Build.BuildNumber)" > buildinfo.txt'
  displayName: 'Write build info'
  workingDirectory: $(wwwrootDir)

- task: DotNetCoreCLI@2
  displayName: 'Restore project dependencies'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Build the project - $(buildConfiguration)'
  inputs:
    command: 'build'
    arguments: '--no-restore --configuration $(buildConfiguration)'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Install .NET tools from local manifest'
  inputs:
    command: custom
    custom: tool
    arguments: 'restore'

- task: DotNetCoreCLI@2
  displayName: 'Run unit tests - $(buildConfiguration)'
  inputs:
    command: 'test'
    arguments: '--no-build --configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/'
    publishTestResults: true
    projects: '**/*.Tests.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Create code coverage report'
  inputs:
    command: custom
    custom: tool
    arguments: 'run reportgenerator -reports:$(Build.SourcesDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage report'
  inputs:
    codeCoverageTool: 'cobertura'
    summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'

- task: DotNetCoreCLI@2
  displayName: 'Publish the project - $(buildConfiguration)'
  inputs:
    command: 'publish'
    projects: '**/*.csproj'
    publishWebProjects: false
    arguments: '--no-build --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
    zipAfterPublish: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  condition: succeeded()

This question is related to the following Learning Module

Azure | Azure Training
0 comments No comments
{count} votes

Accepted answer
  1. Pradeep M 9,765 Reputation points Microsoft External Staff Volunteer Moderator
    2024-11-25T04:51:15.63+00:00

    Hi Hassaan Faruq,

    Thank you for reaching out to Microsoft Q & A forum.  

    This module was originally designed to use .NET SDK 6.0, meaning that the instructions and configurations are optimized for that version. However, due to recent tool updates, some packages, such as dotnet-reportgenerator-globaltool, only support .NET 8.0 or higher. 

    To complete the exercises smoothly, we recommend the following options: 

    Use .NET SDK 8.0: The latest versions of tools like ReportGenerator are only compatible with .NET 8.0. We suggest installing .NET SDK 8.0 and updating your project settings accordingly. You can download .NET SDK 8.0 from Microsoft's .NET downloads page. 

    1.Update the SDK version: Open the project’s .csproj file and set the target framework to net8.0: 

    <TargetFramework>net8.0</TargetFramework>
    

    2.Adjust your pipeline: Update the Azure Pipelines YAML file to target .NET 8.0 by specifying dotnetSdkVersion: '8.x' in the UseDotNet@2 task: 

    variables:
      dotnetSdkVersion: '8.x'
    

    3.Check and update dependencies: Ensure that any dependencies, such as coverlet.msbuild and ReportGenerator, are compatible with .NET 8.0 by updating them to the latest versions. 

    4.Test the setup: After making these changes, run tests to confirm that code coverage reports and other functions perform correctly with .NET 8.0. 

    Note for Future Updates:  This module may be updated to include support for newer SDKs in the future. For now, using .NET SDK 8.0 will allow you to complete the exercises without compatibility issues. 

    Please feel free to contact us if you have any additional questions.    

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.   

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.