I would like to have Sonar scanner running on my project when it builds in jenkins.
Something like this,
Most of the tutorials seem to only address this process from a Java perspective, So I am wondering how this can be done if at all.
I am doing some of the work out of a Jenkinsfile in my project:
stage('SonarQube') {
environment {
scannerHome = tool 'SonarQubeScanner'
}
steps {
withSonarQubeEnv('SonarQubeScanner') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
I used the following link to get the project in SonarQube: https://nickkorbel.com/2020/02/05/configuring-sonar-with-a-create-react-app-in-typescript/
I get a couple different errors when the scan tries to run during the Jenkins Build:
Error 1
Could not find executable in "/opt/app-root/src/.sonar/native-sonar-scanner".
Proceed with download of the platform binaries for SonarScanner...
Creating /opt/app-root/src/.sonar/native-sonar-scanner
Downloading from https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.4.0.2170-linux.zip
(executable will be saved in cache folder: /opt/app-root/src/.sonar/native-sonar-scanner)
ERROR: impossible to download and extract binary: connect ETIMEDOUT
Error 2
ERROR: Failed to download https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.4.0.2170-linux.zip from agent; will retry from master
SonarQube installation defined in this job (sonarqube) does not match any configured installation. Number of installations that can be configured: 1.
Error 2 is about missing integration with sonarqube server.
Full install of sonarqube:
withSonarQubeEnv('SonarQubeScanner')
- "SonarQubeScanner" means the name of the Sonarqube server from step 3.
In the pipeline you should pass parameters for sonar-scanner tool, for example:
stage('SonarQube analysis') {
environment {
scannerHome = tool 'SonarQube_4.3.0'
}
steps {
withSonarQubeEnv('Your Sonar Server Name here') {
sh '''
${scannerHome}/bin/sonar-scanner \
-D sonar.projectKey=YOUR_PROJECT_KEY_HERE \
-D sonar.projectName=YOUR_PROJECT_NAME_HERE \
-D sonar.projectVersion=YOUR_PROJECT_VERSION_HERE \
-D sonar.languages=js,ts \ // DEPRECATED, do not use this option
-D sonar.sources=./src \
-D sonar.test.inclusions=YOUR_INCLUSIONS_HERE \
-D sonar.exclusions=YOUR_EXCLUSIONS_HERE
'''
}
}
}
Suppose Error 1 will be fixed after you fix Error 2. Take a look at official documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With