admin管理员组文章数量:1401233
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: /
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 .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 .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.
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./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./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./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.
Share
Improve this question
edited Jul 13, 2020 at 13:22
Jub10
asked Jul 13, 2020 at 13:16
Jub10Jub10
3132 gold badges3 silver badges20 bronze badges
2 Answers
Reset to default 4Error 2 is about missing integration with sonarqube server.
Full install of sonarqube:
- Install SonarQube server
- Install the SonarQube Scanner plugin for Jenkins.
- Configure your SonarQube server(s):
- Log into Jenkins as an administrator and go to Manage Jenkins > Configure System.
- Scroll down to the SonarQube configuration section, click Add SonarQube, and add the values you're prompted for.
- The server authentication token should be created as a 'Secret Text' credential.
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
In my case any ways to init scannerHome
var were unsuccessful. So I did it my way:
stage("SonarQube analysis") {
steps {
script {
withSonarQubeEnv('SonarQube Server') {
sh '''
${JENKINS_HOME}/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/bin/sonar-scanner \
-Dsonar.host.url=URL_TO_SONAR \
-Dsonar.login=SONAR_TOKEN \
-Dsonar.projectKey=PROJECT_KEY \
-Dsonar.projectName=PROJECT_NAME
'''
}
}
}
}
本文标签: javascriptHow to setup SonarQube scanner in jenkins for a jstsreact projectStack Overflow
版权声明:本文标题:javascript - How to setup SonarQube scanner in jenkins for a jstsreact project - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744270667a2598167.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论