/dotnet-sonarqube-msbuild-pipeline

Sample project used to build a C/.net project and send information to sonarqube server

Primary LanguageGroovy

dotnet-sonarqube-msbuild-pipeline

Sample project used to build a C/.net project and send information to sonarqube server.

##Jenkins configuration: Jenkins must have SonarQube server and SonarScanner for MSBuild configured to be able to run SonarQube scans and send reports to the server.

SonarQube MSBuild server

This step must be done in every Jenkins Controller that will use this node to run builds and send reports to SonarQube server.

  1. Navigate to Jenkins//Manage Jenkins/Configure system
  2. Under 'SonarQube servers' click 'Add SonarQube' to add a new entry called 'SonarQubeMSBuild' with our production SonarQube server info
    1. Name: SonarQubeMSBuild
    2. Server URL: https://
    3. Server authentication token: Select the credential which allows jenkins in sonarqube (Sonarqube user)
    4. Example: image
  3. Save

SonarScanner for MSBuild Global tool

This step must be done in every Jenkins Controller that will use this node to run builds and send reports to SonarQube server.

  1. Navigate to Jenkins//Manage Jenkins/Global Tool Configuration
  2. Under 'SonarScanner for MSBuild' Click 'Add SonarScanner for MSBuild' to add a new installation
    1. Name: SonarQubeMSBuild
    2. Check 'Install automatically' option
    3. Version: Pick the latest version
    4. Example: image
  3. Save

Install build-wrapper-win-x86-64.exe

Install build-wrapper:

  1. Download it from https:///static/cpp/build-wrapper-win-x86.zip
  2. Unzip it to the desired folder
  3. Add it to the PATH environment variable

Installation files

After the first Jenkins pipeline run, Jenkins will install the SonarScanner for MSBuild Global files under: /tools. Example: image

Reports

The pipeline refered in the Jenkinsfile in this repo would build the projects and send reports to SonarQube server. NOTE: It makes the build time to increase a lot. Maybe due to the process of indexing the files to send reports.

Examples: image

References:

https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/ https://docs.sonarqube.org/latest/analysis/languages/cfamily/ https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/ https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/ https://stackoverflow.com/questions/58558449/sonarscanner-msbuild-tool-is-not-running-in-pipeline-jenkins https://community.sonarsource.com/t/sonarscanner-msbuild-exe-and-build-wrapper-win-x86-64-exe/25460 https://community.sonarsource.com/t/sonarcloud-with-msbuild-build-wrapper-on-github-actions/35607 https://community.sonarsource.com/t/jenkins-declarative-pipeline-with-sonarcube-and-msbuild/36964