integrating sonarqube with jenkins insufficient privileges error - jenkins

I followed this video https://www.youtube.com/watch?v=jh7utASgKj4 to integrate sonarqube with jenkins. However, I get the insufficient privileges error when scanning the code by sonarqube server. The version of sonarqube server is 6.7. how can I solve this problem?
Here is the analysis properties in the jenkins project
# Required metadata
sonar.projectKey = test-sonar
# Path to source directory
sonar.sources = /var/jenkins_home/workspace/$JOB_NAME/test-sonar/src
# bind sonar.java.binaries property
sonar.java.binaries=/var/jenkins_home/workspace/$JOB_NAME/test-sonar/target/classes
Here is the output of console.
INFO: SCM provider for this project is: git
INFO: 16 files to be analyzed
INFO: 16/16 files analyzed
INFO: 5 files had no CPD blocks
INFO: Calculating CPD for 8 files
INFO: CPD calculation finished
INFO: Analysis report generated in 132ms, dir size=124 KB
INFO: Analysis reports compressed in 48ms, zip size=61 KB
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 48.028s
INFO: Final Memory: 15M/304M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Insufficient privileges
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succedeed?
ERROR: SonarQube scanner exited with non-zero code: 1

If you are running the Sonar Analysis via Execute shell plugin for Jenkins, you need to supply the Username Password of a User which has the Execute Analysis rights on the SonarQube server you are trying to access.
To supply the username in the shell, you can use
-Dsonar.login=yourLoginName -Dsonar.password=*****
To set the Execute Analysis permission you can ask your DevOps team to give you access or if you are looking into that,
Goto Administration > Security > User/Groups.

Please make sure that you configure the Sonarqube UserID and Password having privileges to access sonar server (execute analysis permissions) in the Sonar plugin for Jenkins. This error might appear for 5.3 and higher versions when the anonymous access to sonar is disabled.

Related

How to avoid "GC overhead limit exceeded"?

Our Sonar Build Environment details as follows:
* SonarQube Server Version - 5.6.7 (64-Bit).
* Sonar Client Build Operating System – Ubuntu-14.04 (LTS - 64-Bit).
* Sonar Build machine total RAM: 16-GB.
* Sonar-Scanner- Version - 3.0.3.778.
* sonar-cxx-plugin-0.9.7.jar
* Source Code Language: C++
* Client Machine Java Version: 1.8
* Source Code Size: 62-GB.
Problem:
Through Jenkins sonar-scanner finished successfully (Log as follows).
Jenkins Sonar-Scanner Build Log:
12:24:14 INFO: CPD calculation finished
12:26:35 INFO: Analysis report generated in 136049ms, dir size=1 GB
12:49:25 INFO: Analysis reports compressed in 1369236ms, zip size=385 MB
12:49:43 INFO: Analysis report uploaded in 18811ms
12:49:43 INFO: ANALYSIS SUCCESSFUL, you can browse http://sonarqube-server/dashboard/index/scm.project.4.0
12:49:43 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
12:49:43 INFO: More about the report processing at http://sonarqube-server/api/ce/task?id=AV-af9So2HbsBuSrsvrw
12:50:22 INFO: ------------------------------------------------------------------------
12:50:22 INFO: EXECUTION SUCCESS
Whereas Sonarqube project dashboard shows "No analysis has been performed since creation. The only available section is the configuration." And also under SonarQube Web--> Project--> Administration-->Background Tasks-->Logs shows below errors.
Error:
2017.11.07 13:04:23 ERROR [o.s.s.c.t.CeWorkerCallableImpl] Failed to execute task AV-VUEIr2HbsBuSrsvnY
java.lang.OutOfMemoryError: GC overhead limit exceeded
I have tried the following, still same problem persists.
Tried with SONAR_RUNNER_OPTS option with -Xmx10240m -XX:MaxPermSize=1024m -XX:ReservedCodeCacheSize=128m
Then in sonar-project.properties file I have added sonar.ce.javaOpts=-Xmx1280m & sonar.web.javaOpts=-Xmx1280m
Or still I need to increase the build machine RAM (or) 16-GB is sufficient for 62-GB Code?
You need to upgrade the memory allocated for Compute Engine on the server side not on the scanner side (for this particular issue).
So on your SonarQube server, update the following parameter :
sonar.ce.javaOpts=-Xmx2G -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true
It will allow Compute Engine which will integrate your report to consume 2Gb of memory (by default it's 512Mb).

Error during SonarQube Scanner execution from Jenkins plugin

I get the following error when I try to execute SonarQube Scanner as a part of Jenkins build:
ERROR: SonarQube server [http://<hostname>:9000] can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.242s
INFO: Final Memory: 5M/483M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory$1.run(IsolatedLauncherFactory.java:84)
at
... 8 more
Caused by: java.lang.IllegalStateException: Status returned by
url [http://<hostname>:9000/batch/index] is not valid: [404]
at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:115)
at org.sonarsource.scanner.api.internal.Jars.getBootstrapIndex(Jars.java:96)
... 12 more
ERROR:
I can access the following URL from my Jenkins host: http://:9000/sonar/ . When I try to execute this:
wget http://<hostname>:9000/batch/index
I get the same 404 http error in response. I have no idea from where this URL postfix /batch/index comes from. Web search did not give any clues for this.
My Sonar version is 6.0. My Jenkins Sonar Scanner plugin version is 2.6.1.
Used JVM:
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
What is your the setting for sonar's web context (sonar.web.context) on your sonar server? It would be inside of sonar.properties. By default both the Jenkins plugin and the sonar server configuration set it to root:
'http://<hostname>:9000/'
The first thing I would do is to make sure those are matching in the sonar configuration and the jenkins plugin configuration.
I've seen tutorials that tell you to use /sonar or something similar. In that case, the jenkins plugin would need to be set to /sonar as well, like:
'http://<hostname>:9000/sonar'

How to filter files in sonar SCM?

I have installed a CI environment for my PHP project.
I use jenkins + sonar + Gitlab.
All things seem great until build a jenkins job.
The error info is
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 2:03.218s
Final Memory: 345M/456M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: Unable to blame file src/apps/conf.php. No blame info at line 1. Is file commited?
10:21:17.165 INFO - Author: PersonIdent[Not Committed Yet, , Wed Feb 4 10:21:17 2015 +0800]
ERROR:
I find sonar SCM-Activity-Plugin report this bug.
The conf.php file is my config file and can not push to Gitlab.
So, Is there a way to ask SCM-Activity-Plugin filter these config files?
thanks a lot!
Excluding the file from sonar analysis might help.
Login to sonar using admin or user that have got administrative rights in the project.
Open the project and select “Settings” from “Project Configuration”.
There click on “Exclusions” link and take “File” tab.
Under “Source File Exclusions” give your file as src/apps/conf.php

Sonar Runner does not use properties of sonar-project.properties

I am using SonarQube Runner 2.4 at jenkins since today but the analysis fail with the message:
SonarQube Runner 2.4
Java 1.7.0_51 Oracle Corporation (64-bit)
INFO: Runner configuration file: /.jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Sonar_Runner_2.4/conf/sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "ISO-8859-1" (analysis is platform dependent)
INFO: Work directory: /.jenkins/workspace/Sonar/.sonar
INFO: SonarQube Server 4.3.2
23:21:42.176 INFO - Load batch settings
23:21:42.160 INFO - User cache: /.sonar/cache
23:21:42.270 INFO - Install plugins
23:21:43.322 INFO - Install JDBC driver
23:21:43.329 INFO - Create JDBC datasource for jdbc:mysql://xxx
23:21:45.505 INFO - Initializing Hibernate
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 5.214s
Final Memory: 21M/429M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must define the following mandatory properties for ‚com.mypackage:MyProject: sonar.sources
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
Build step 'Invoke Standalone Sonar Analysis' marked build as failure
[BFA] Scanning build for known causes...
[BFA] Done. 0s
Notifying upstream projects of job completion
Finished: FAILURE
If I add the property "MyProject.sonar.sources=src" In the project properties in Jenkins (I use "Invoke Standalone Sonar Analysis"). I will receive the error message
ERROR: Caused by: Findbugs needs sources to be compiled. Please build project before executing sonar and check the location of compiled classes.
This means the sonar-project.properties (/.jenkins/workspace/Deploy/MyProject/sonar-project.properties) is not read or used because there are all values defined:
sonar.language=java
sonar.projectName=MyProject
sonar.projectVersion=0.1
sonar.binaries=bin
sonar.projectDescription=
sonar.projectKey=MyProjectKey
sonar.sources=src
When sonar is executed I can see the correct path to MyProject where :
-DMyProject.sonar.projectBaseDir=/.jenkins/workspace/Deploy/MyProject
Or does the name of sonar-project.properties changed?
Please build the project in the release mode. After the build happens you will get the dll's produced somewhere. you have to point to that location.

SonarQube Runner 2.4 can not find sonar.sources in sonar-project.properties even it exist

I am using SonarQube Runner 2.4 at jenkins since today but the analysis fail with the message:
SonarQube Runner 2.4
Java 1.7.0_51 Oracle Corporation (64-bit)
INFO: Runner configuration file: /.jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Sonar_Runner_2.4/conf/sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "ISO-8859-1" (analysis is platform dependent)
INFO: Work directory: /.jenkins/workspace/Sonar/.sonar
INFO: SonarQube Server 4.3.2
23:21:42.176 INFO - Load batch settings
23:21:42.160 INFO - User cache: /.sonar/cache
23:21:42.270 INFO - Install plugins
23:21:43.322 INFO - Install JDBC driver
23:21:43.329 INFO - Create JDBC datasource for jdbc:mysql://xxx
23:21:45.505 INFO - Initializing Hibernate
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 5.214s
Final Memory: 21M/429M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must define the following mandatory properties for ‚com.mypackage:MyProject: sonar.sources
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
Build step 'Invoke Standalone Sonar Analysis' marked build as failure
[BFA] Scanning build for known causes...
[BFA] Done. 0s
Notifying upstream projects of job completion
Finished: FAILURE
But sonar-project.properties of My_Project contain sonar.sources.
sonar.language=java
sonar.projectName=My_Project
sonar.projectVersion=0.1
sonar.binaries=bin
sonar.projectDescription=
sonar.projectKey=MyProjectKey
sonar.sources=src
Where is the problem?
Greetings
Try adding "sonar.sources=." See if this works or not. Please add the log if the problem still persists.
sonar.sources and sonar.binaries path should be relative to the sonar runner home. You need to check that of the path is right as just src.

Resources