All things Tech with a dash of Geek for good measure!

Archive for May, 2020

NopCommerce 4.3 build pipeline on VisualStudio Online (Azure-Devops) with code coverage!

Following on from the previous article, to add Code coverage to nopcommerce when building on Azure-Pipeline as your dev-ops pipeline, it is necessary to add the following nugets to the nopcommerce test projects:

Install Microsoft.CodeCoverage to the 4 test projects:

Microsoft.Codecoverage

Install coverlet.collector to the 4 test projects:

coverlet.collector

 

It is also necessary to adjust your build pipeline, you can do this using the following in your `azure-pipelines.yml`

pool:
name: Azure Pipelines

steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
   command: restore
   projects: ./src/NopCommerce.sln

- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
   projects: ./src/NopCommerce.sln
   arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
   command: test
   projects: |
     ./src/Tests/Nop.Core.Tests/Nop.Core.Tests.csproj
     ./src/Tests/Nop.Web.MVC.Tests/Nop.Web.MVC.Tests.csproj
     ./src/Tests/Nop.Services.Tests/Nop.Services.Tests.csproj
   arguments: '--configuration $(BuildConfiguration) --collect "XPlat Code coverage"'

- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
   codeCoverageTool: Cobertura
   summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'

- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
   command: publish
   arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
   ArtifactName: '$(Parameters.ArtifactName)'

This will allow full code coverage results:

codecoverageresults

If only SonarCube was also enabled ;-p but we are not the authors, so that is for another tutorial!

NopCommerce 4.3 build pipeline on VisualStudio Online (Azure-Devops / VSTS )

So it is time to upgrade your nopcommerce install to the latest and greatest… Like me, you have given up on Travis, want to customise the source and use Azure-Pipeline as your dev-ops pipeline…

Given that you are Competent with Git and have https://github.com/marketplace/azure-pipelines enabled in your repo, it is quite simple… just create the following `azure-pipelines.yml` file in the root folder of your repo, and (subject to adding the extension to GitHub), away you go!

pool:
  name: Azure Pipelines
steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: ./src/NopCommerce.sln
- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    projects: ./src/NopCommerce.sln
    arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
    command: test
    projects: |
     ./src/Tests/Nop.Core.Tests/Nop.Core.Tests.csproj
     ./src/Tests/Nop.Web.MVC.Tests/Nop.Web.MVC.Tests.csproj
     ./src/Tests/Nop.Services.Tests/Nop.Services.Tests.csproj
    arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: publish
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    ArtifactName: '$(Parameters.ArtifactName)'

In the next part, we shall see if we can get Code Coverage working (although you might be disappointed by the results!)

Tag Cloud