Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to setup a Jenkins declarative pipeline that also includes SonarQube scan as part of the stages but i have not come across a fairly straghtforward guide for the process.

This is my toolset :

Jenkins – ver 2.223

SonarQube – ver 8.6.0.39681

Sonar Runner – sonar-runner-dist-2.4

SonarScanner for MSBuild 4.6.1.2049

.Net Framework 4.6 (same as my project’s version)

I have a couple of questions regarding how i can setup this :

Do i need to add a sonar-project.properties file also and if so where should i place it … at the Project root in my Visual Studio workspace or ONLY in the Jenkins workspace

If mantained in VS workspace do i need to checkout this file into source control

If i have to add a sonar-project.properties file is the content below sufficient :

What I have tried:

<pre lang="c#"><pre>sonar.projectKey=<>
sonar.projectName=
sonar.projectVersion=1.0
sonar.login=
sonar.sources=src
sonar.exclusions=/*.doc,/.docx,*/.ipch,/node_modules/,
sonar.host.url=http:///


If i am going to need the file what values should i use for the following:

sonar.projectKey=<> (Where do i get this ? Do i need to create a project in SonarQube server and if so any links for the procedure)

sonar.projectName= (I am going to put the name of my project . Is this correct ?)

sonar.projectVersion=1.0 (Can i skip this. If not what should i put here)

sonar.login= (What value is this? Should i put the Jenkins token generated in SonarQube webhook. If not what do i put here)

sonar.sources=src (What value should i put here? My project is a .net mvc project. No idea what path to use )

sonar.exclusions=/.doc,/.docx,/.ipch,/node_modules/, (What value should i put here? Can i skip this)

sonar.host.url=http:/// (What value should i put here? Is http://localhost:9000 correct ? )

I have written my pipeline in Jenkins as below :
pipeline {
         agent any
         stages {
             stage('Checkout'){
                 steps{                       
                     checkout([$class: 'GitSCM', branches: [[name: '*/develop']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'Fredo', url: 'https://github.com/Ed877/FinSys.git
                     ']]])
                 }
             }
             stage('Build') {
                     steps {
                         bat "\"${tool 'MSBuild'}\" PaySys.sln /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /t:build /p:Configuration=Release /p:Platform=\"Any CPU\" /p:DeleteExistingFiles=True /p:publishUrl=c:\\inetpub\\wwwroot\\"
                     }
             }
             stage('Quality Gate') {
             environment {
 scannerHome = tool 'MSBuild_SonarScanner'
   }     
 steps {
 withSonarQubeEnv('LocalSonar') {
   echo "${scannerHome}"
   bat "${scannerHome}\\SonarScanner.MSBuild.exe begin /k:{project-key} /n:{project-name} /v:build"
  bat 'msbuild project.sln /t:Rebuild /p:Configuration=Release'
   bat "${scannerHome}\\SonarScanner.MSBuild.exe end"
 }
   }

    }
         }
 }


Is the pipeline implementation for Sonar correct ? If so what values should i use for :

/k:{project-key} (Do i use project key as in sonar-project.properties file )

/n:{project-name} (Do i use project name as in sonar-project.properties file )

bat 'msbuild project.sln ...... ' (Do i need to put full path of project here and if so is this path correct : C:\Users\username\source\repos\PaySys\PaySys.sln)

jenkins
Posted
Comments
[no name] 15-Jan-21 8:20am    
Considering the number of questions, the answer seems to be you need to do more reading and / or rethink why you're on this path in the first place.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900