Sign inSign up

ruanzx/dotnet-sonarscanner

By ruanzx

•Updated over 2 years ago

Dotnet core with sonar scanner

Image
0

523

ruanzx/dotnet-sonarscanner repository overview

⁠Usage

Create sonarqube server docker-compose.sonar.yml

$ docker-compose -f docker-compose.sonar.yml up -d
version: '3.6'

networks:
  sonar:
    name: sonar
    driver: bridge

volumes: 
  sonarqube-data:
    driver: local 
  sonarqube-logs:
    driver: local  

services:

  sonarqube:
    image: sonarqube:7.9.2-community
    container_name: sonarqube
    restart: always
    volumes: 
      - sonarqube-data:/opt/sonarqube/data
      - sonarqube-logs:/opt/sonarqube/logs
    networks:
      - sonar
    ports:
      - "9000:9000"

Execute sonarscanner

$ docker run -it --rm `
  --name sonarscanner `
  --network sonar `
  -e SONAR_SCANNER_OPTS="-Xmx512m" `
  -v ${pwd}/:/workspace `
  -v nuget-cache:/root/.nuget `
  -v nuget-http-cache:/.local/share/NuGet `
ruanzx/dotnet-sonarscanner `
/bin/bash -c `
"cd /workspace \
&& rm -Rf .sonarqube test-report \
&& dotnet sonarscanner begin /s:'/workspace/SonarQube.Analysis.xml' /v:'1.0' /key:'98098696a83cbb3eea8fd814e150c47e89b2c945' \
&& dotnet build TOpenLand.sln \
&& dotnet test \
   --verbosity minimal \
   --list-tests \
   --results-directory ./test-report/unit-tests \
   --logger 'trx;LogFileName=./test-report/report.trx' \
   /p:CollectCoverage=true \
   /p:CoverletOutputFormat=cobertura \
   /p:Exclude=[xunit.*]* \
&& reportgenerator \
  '-reports:src/**/coverage.cobertura.xml' \
  '-targetdir:test-report/coverage' \
  '-reporttypes:HtmlInline_AzurePipelines;Cobertura;SonarQube' \
  '-historydir:test-report/history' \
&& dotnet sonarscanner end"

SonarQube.Analysis.xml

<SonarQubeAnalysisProperties  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">
<Property Name="sonar.projectName">project1</Property>
<Property Name="sonar.projectDescription">project1</Property>
<Property Name="sonar.projectBaseDir">.</Property>
<Property Name="sonar.host.url">http://sonarqube:9000</Property>
<Property Name="sonar.sourceEncoding">utf-8</Property>
<!-- 
  <Property Name="sonar.login">98098696a83cbb3eea8fd814e150c47e89b2c945</Property>
--> 
<Property Name="sonar.login">admin</Property>
<Property Name="sonar.password">admin</Property>

<!-- source files filter -->
<Property Name="sonar.sources">src/**/*.cs,src/**/*.ts,src/**/*.tsx</Property>
<!-- <Property Name="sonar.inclusions"></Property> -->
<Property Name="sonar.exclusions">node_modules/**,**/types/**,wwwroot/**,**/*.html,**/*.json,**/*.yml,**/*.xml,**/*.xlsx,**/*.spec.ts,obj/**,bin/**</Property>

<Property Name="sonar.tests">*.FunctionalTests,*.UnitTests,*.IntegrationTests</Property>
<!-- 
<Property Name="sonar.test.inclusions">**/**.cs</Property>
<Property Name="sonar.test.exclusions">**/**.cs</Property>
-->
 
<Property Name="sonar.coverageReportPaths">test-report/coverage/SonarQube.xml</Property>
<Property Name="sonar.cs.cobertura.reportsPaths">src/**/coverage.cobertura.xml</Property>
<!--  
<Property Name="sonar.cs.opencover.reportsPaths">src/**/coverage.opencover.xml</Property> 
  -->
<Property Name="sonar.ws.timeout">60</Property>
<Property Name="sonar.log.level">DEBUG</Property>
<Property Name="sonar.verbose">false</Property>
</SonarQubeAnalysisProperties>

Tag summary

Content type

Image

Digest

Size

507.9 MB

Last updated

over 6 years ago

docker pull ruanzx/dotnet-sonarscanner