Azure devops 从Azure DevOps管道使用Cobertura文件覆盖SonarQube的代码
我有一个dotnet核心版本:“3.0.100”,建立在“ubuntu16.04”的基础上,我正试图将代码覆盖率推到我们的自托管SonarQube上 我一直在使用生成Cobertura文件,然后可以使用PublishCodeCoverageResults@1发布到Devops pipelines代码覆盖率查看器 但是,我无法将cobertura.xml文件推送到sonarqube 我读过,在我看来,唯一提到的cobertura是python和flex。有可能用那个文件来报道我的C#项目吗 我一直在玩弄以下内容,但怀疑我在extraProperties中的内容是不正确的Azure devops 从Azure DevOps管道使用Cobertura文件覆盖SonarQube的代码,azure-devops,sonarqube,Azure Devops,Sonarqube,我有一个dotnet核心版本:“3.0.100”,建立在“ubuntu16.04”的基础上,我正试图将代码覆盖率推到我们的自托管SonarQube上 我一直在使用生成Cobertura文件,然后可以使用PublishCodeCoverageResults@1发布到Devops pipelines代码覆盖率查看器 但是,我无法将cobertura.xml文件推送到sonarqube 我读过,在我看来,唯一提到的cobertura是python和flex。有可能用那个文件来报道我的C#项目吗 我一直
- task: SonarQubePrepare@4
inputs:
SonarQube: 'My SonarQube'
scannerMode: 'MSBuild'
projectKey: 'dcap'
projectName: 'DCAP'
extraProperties: 'sonar.flex.cobertura.reportPaths=**/DCAP.Testing.Unit/TestResults/*/coverage.cobertura.xml'
谢谢:-)
有可能用那个文件来报道我的C#项目吗
恐怕没有这种开箱即用的属性来涵盖Cobertura
格式的C#
项目
正如您所读到的,cobertura是python和flex的代表。对于C#,我们需要使用sonar.cs.dotcover.reportspath
或sonar.cs.opencover.reportspath
格式的dotcover
或opencover
要解决此问题,您可以尝试使用Chameera Dulanga提供的自定义powershell脚本作为解决方案:
$Env:DOTNET_ROOT= (Get-Command dotnet).Path.Replace('dotnet.exe','sdk\2.1.300')
dotnet tool install dotnet-reportgenerator-globaltool --tool-path . --version 4.0.12
dotnet tool install coverlet.console --tool-path . --version 1.4.1
mkdir .\reports
$testDll = gci -Recurse | ?{ $_.FullName -like ("*bin\{0}\{1}" -f "$(BuildConfiguration)", "$(TestDllFile)") }
$coverlet = "$pwd\coverlet.exe"
& $coverlet $testDll.FullName --target "dotnet" --targetargs ("vstest {0} --logger:trx" -f $testDll.FullName) --format "cobertura"
gci -Recurse |
?{ $_.Name -eq "coverage.cobertura.xml"} |
%{ &"$pwd\reportgenerator.exe" ("-reports:{0}" -f $_.FullName) "-targetdir:reports" "-reportstypes:HTMLInline;HTMLChart" }
你可以查看他的博客了解一些细节
希望这有帮助
有可能用那个文件来报道我的C#项目吗
恐怕没有这种开箱即用的属性来涵盖Cobertura
格式的C#
项目
正如您所读到的,cobertura是python和flex的代表。对于C#,我们需要使用sonar.cs.dotcover.reportspath
或sonar.cs.opencover.reportspath
格式的dotcover
或opencover
要解决此问题,您可以尝试使用Chameera Dulanga提供的自定义powershell脚本作为解决方案:
$Env:DOTNET_ROOT= (Get-Command dotnet).Path.Replace('dotnet.exe','sdk\2.1.300')
dotnet tool install dotnet-reportgenerator-globaltool --tool-path . --version 4.0.12
dotnet tool install coverlet.console --tool-path . --version 1.4.1
mkdir .\reports
$testDll = gci -Recurse | ?{ $_.FullName -like ("*bin\{0}\{1}" -f "$(BuildConfiguration)", "$(TestDllFile)") }
$coverlet = "$pwd\coverlet.exe"
& $coverlet $testDll.FullName --target "dotnet" --targetargs ("vstest {0} --logger:trx" -f $testDll.FullName) --format "cobertura"
gci -Recurse |
?{ $_.Name -eq "coverage.cobertura.xml"} |
%{ &"$pwd\reportgenerator.exe" ("-reports:{0}" -f $_.FullName) "-targetdir:reports" "-reportstypes:HTMLInline;HTMLChart" }
你可以查看他的博客了解一些细节
希望这有帮助。解决方案是告诉coverlet在一次执行单元测试套件时发出cobertura和opencover结果文件
使用两个文件,您可以发布用于Azure DevOps的cobertura one代码覆盖率选项卡,并通过extraProperties将opencover one提供给SonarQubePrepare
这里是我的管道中重要部分的摘录
variables:
APEX_SOLUTION: 'Redacted.sln'
BUILD_CONFIGURATION: 'Release'
ARTIFACTORY_ROOT: 'Artifactory'
REPOSITORY_CODE: 'redacted-generic-local'
PRODUCT_PREFIX: 'BLAH'
REPOSITORY_GROUP: 'Some/Path'
REPOSITORY_APPLICATION: 'REDACTED'
PUBLISH_FOLDER: 'publish'
PACKAGING_FOLDER: 'packaging'
COBERTURA_OUTPUT: 'coverage.cobertura.xml'
OPENCOVER_OUTPUT: 'coverage.opencover.xml'
IS_INTEGRATION_BRANCH: $[eq(variables['Build.SourceBranch'], 'refs/heads/develop')]
SONAR_SERVER_ENDPOINT: 'SonarQube'
SONAR_PROJECT_KEY: 'redacted-web'
SONAR_PROJECT_NAME: 'REDACTED-Web'
.
.
.
- task: SonarQubePrepare@4
displayName: 'Prepare analysis on SonarQube'
inputs:
SonarQube: $(SONAR_SERVER_ENDPOINT)
scannerMode: MSBuild
configMode: manual
projectKey: $(SONAR_PROJECT_KEY)
projectName: $(SONAR_PROJECT_NAME)
extraProperties: |
sonar.cs.opencover.reportsPaths="$(Build.SourcesDirectory)/TestResults/Coverage/$(OPENCOVER_OUTPUT)"
sonar.cs.nunit.reportsPaths="$(Agent.BuildDirectory)/TestResult.xml"
sonar.scm.exclusions.disabled=true
sonar.exclusions=Redacted/wwwroot/**
sonar.branch.name=$(Build.SourceBranchName)
sonar.projectVersion=$(Build.BuildNumber)
.
.
.
- task: DotNetCoreCLI@2
displayName: 'Unit Tests'
inputs:
command: 'test'
projects: '$(APEX_SOLUTION)'
arguments: '--configuration $(BUILD_CONFIGURATION) --logger "nunit;LogFilePath=$(Agent.BuildDirectory)/TestResult.xml" /p:CollectCoverage=true /p:CoverletOutputFormat="cobertura%2copencover" /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/ /p:Threshold=50 /p:ThresholdType=branch /p:ThresholdStat=Average /p:Exclude="[Redacted.Views]*"'
publishTestResults: true
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage report'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: "$(Build.SourcesDirectory)/**/$(COBERTURA_OUTPUT)"
.
.
.
解决方案是告诉coverlet在一次执行单元测试套件时发出cobertura和opencover结果文件
使用两个文件,您可以发布用于Azure DevOps的cobertura one代码覆盖率选项卡,并通过extraProperties将opencover one提供给SonarQubePrepare
这里是我的管道中重要部分的摘录
variables:
APEX_SOLUTION: 'Redacted.sln'
BUILD_CONFIGURATION: 'Release'
ARTIFACTORY_ROOT: 'Artifactory'
REPOSITORY_CODE: 'redacted-generic-local'
PRODUCT_PREFIX: 'BLAH'
REPOSITORY_GROUP: 'Some/Path'
REPOSITORY_APPLICATION: 'REDACTED'
PUBLISH_FOLDER: 'publish'
PACKAGING_FOLDER: 'packaging'
COBERTURA_OUTPUT: 'coverage.cobertura.xml'
OPENCOVER_OUTPUT: 'coverage.opencover.xml'
IS_INTEGRATION_BRANCH: $[eq(variables['Build.SourceBranch'], 'refs/heads/develop')]
SONAR_SERVER_ENDPOINT: 'SonarQube'
SONAR_PROJECT_KEY: 'redacted-web'
SONAR_PROJECT_NAME: 'REDACTED-Web'
.
.
.
- task: SonarQubePrepare@4
displayName: 'Prepare analysis on SonarQube'
inputs:
SonarQube: $(SONAR_SERVER_ENDPOINT)
scannerMode: MSBuild
configMode: manual
projectKey: $(SONAR_PROJECT_KEY)
projectName: $(SONAR_PROJECT_NAME)
extraProperties: |
sonar.cs.opencover.reportsPaths="$(Build.SourcesDirectory)/TestResults/Coverage/$(OPENCOVER_OUTPUT)"
sonar.cs.nunit.reportsPaths="$(Agent.BuildDirectory)/TestResult.xml"
sonar.scm.exclusions.disabled=true
sonar.exclusions=Redacted/wwwroot/**
sonar.branch.name=$(Build.SourceBranchName)
sonar.projectVersion=$(Build.BuildNumber)
.
.
.
- task: DotNetCoreCLI@2
displayName: 'Unit Tests'
inputs:
command: 'test'
projects: '$(APEX_SOLUTION)'
arguments: '--configuration $(BUILD_CONFIGURATION) --logger "nunit;LogFilePath=$(Agent.BuildDirectory)/TestResult.xml" /p:CollectCoverage=true /p:CoverletOutputFormat="cobertura%2copencover" /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/ /p:Threshold=50 /p:ThresholdType=branch /p:ThresholdStat=Average /p:Exclude="[Redacted.Views]*"'
publishTestResults: true
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage report'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: "$(Build.SourcesDirectory)/**/$(COBERTURA_OUTPUT)"
.
.
.
该死的微软。这是垃圾。Azure DevOps中的代码覆盖率选项卡在Linux上运行时使用Coverlet需要cobertura XML。但是,要使覆盖范围与SonarQube一起工作,还需要OpenCover。纠正这一荒谬。随便选一个,该死的微软。这是垃圾。Azure DevOps中的代码覆盖率选项卡在Linux上运行时使用Coverlet需要cobertura XML。但是,要使覆盖范围与SonarQube一起工作,还需要OpenCover。纠正这一荒谬。随便挑一个,谢谢。我现在正在做别的事情,但几个月后应该会回来做这个项目。那我去看看。谢谢。我现在正在做别的事情,但几个月后应该会回来做这个项目。那我去看看。