Use SonarQube
SonarQube is open source quality management software that continuously analyzes your application. When you configure a job to use SonarQube, the build generates an analysis summary that you can view from the job or build details page.
To learn about SonarQube, see its documentation at https://docs.sonarqube.org
.
Create and Manage the Pre-Defined SonarQube Server Connection
You must be the project owner to add and manage SonarQube server connections.
Here's how you can set up a SonarQube system for your project's users and then create and manage a pre-defined SonarQube connection that they can use:
Action | How To |
---|---|
Add a SonarQube connection |
|
Edit a connection to change the user credentials or provide another server ID |
|
Delete the connection |
|
Configure a Job to Connect to SonarQube
You can configure a job to use SonarQube from the Before Build tab and then add a post-build action (on the After Build tab) to publish its reports:
To view the SonarQube analysis summary after a build, from the job’s details page,
click SonarQube Analysis Summary
. The SonarQube Analysis Summary displays SonarQube server URL for the job
and the analysis summary.
Enable SonarQube for Gradle Applications
Use the following steps to enable SonarQube for your Gradle application.
Use a Unix Shell Script to Enable SonarQube for Gradle Applications
You can use a Unix Shell script to enable SonarQube for Gradle applications.
Enable SonarQube for Maven Applications
Use the following steps to enable SonarQube for your Maven application.
Use a Unix Shell Script to Enable SonarQube for Maven Applications
You can use a Unix Shell script to enable SonarQube for Maven applications.
Create a Sonarqube Analysis Report for a VB Studio Project with Javascript Sources
The VB Studio build system supports Sonarqube analysis for Java using Maven and Gradle during building and packaging. This is for Java apps, not visual applications. It doesn't provide built-in support for analyzing Javascript sources. If you need to perform a Sonarqube analysis for Javascript sources, such as those created by VB Studio, you'll need to create your own Sonarqube analysis report by using the Unix Shell builder and then uploading the results to Sonarqube.
- If the project being built is a Maven project, you'll need to direct the Sonar Scanner Maven plugin to include the JS files for analysis.
- If the project is a VB Studio project that is purely Javascript, you'll need to install and use the sonar-scanner command line tool to do the analysis.
Analyze Javascript Sources in a Maven Project
If the project being built is a Maven project, by default, the Sonar
Scanner Maven plugin will include only the Java sources from
src/main/java
. You'll need to make sure the plugin also
includes the Javascript files for analysis:
-
Use the
-Dsonar.source
parameter on the command line to explicitly include the path to the Javascript files, as shown in this example:mvn clean install sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWD -Dsonar.sources=src/main/java,src/main/webapp -Dsonar.projectName=$SONAR_PROJECT_NAME -Dsonar.projectKey=$SONAR_PROJECT_KEY -f UiServer/pom.xml
In the example,
-Dsonar.sources=src/main/java,src/main/webapp
is used to explicitly add Java sources fromsrc/main/java
and Javascript sources fromsrc/main/webapp
. -
The log will show that the Javascript sources were analyzed, as were HTML and CSS files:
[2021-04-01 21:31:30] [INFO] Sensor CSS Metrics [cssfamily] [2021-04-01 21:31:30] [INFO] Sensor CSS Metrics [cssfamily] (done) | time=29ms [2021-04-01 21:31:30] [INFO] Sensor CSS Rules [cssfamily] [2021-04-01 21:31:31] [INFO] 12 source files to be analyzed [2021-04-01 21:31:31] [INFO] 12/12 source files have been analyzed [2021-04-01 21:31:31] [INFO] Sensor CSS Rules [cssfamily] (done) | time=1446ms [2021-04-01 21:31:31] [INFO] Sensor JavaScript analysis [javascript] [2021-04-01 21:31:34] [INFO] 13 source files to be analyzed [2021-04-01 21:31:36] [INFO] 13/13 source files have been analyzed [2021-04-01 21:31:36] [INFO] Sensor JavaScript analysis [javascript] (done) | time=4971ms [2021-04-01 21:31:36] [INFO] Sensor HTML [web] [2021-04-01 21:31:36] [INFO] Sensor HTML [web] (done) | time=137ms
Analyze a VB Studio Project That Contains Javascript Sources Only
For a VB studio project that contains just Javascript sources, you can create a Unix Shell step that downloads and installs the sonar-scanner command line tool, then uses it to perform the analysis:
-
Open the job’s configuration page.
-
Click the Steps tab.
-
From Add Step, select Unix Shell.
-
In Script, enter the following commands:
-
Download the sonar-scanner command line tool from SonarQube website:
curl -o sonar-scanner-cli-4.6.0.2311-linux.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.0.2311-linux.zip
-
Unzip the tool:
unzip sonar-scanner-cli-4.6.0.2311-linux.zip
-
Run the scanner to perform the analysis, after explicitly specifying which Javascript sources you want it to analyze, as in
-Dsonar.sources=UiServer/src/main/webapp
::sonar-scanner-4.6.0.2311-linux/bin/sonar-scanner -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWD -Dsonar.sources=UiServer/src/main/webapp -Dsonar.projectName=$SONAR_PROJECT_NAME -Dsonar.projectKey=$SONAR_PROJECT_KEY
- Click Save.
-
-
Run the build and check the build log to make sure that the analysis was successful:
[2021-04-01 22:12:20] INFO: ------------- Run sensors on module Project1.Sonar_8_8_sonar_scanner [2021-04-01 22:12:20] INFO: Load metrics repository [2021-04-01 22:12:20] INFO: Load metrics repository (done) | time=486ms [2021-04-01 22:12:22] INFO: Sensor CSS Metrics [cssfamily] [2021-04-01 22:12:22] INFO: Sensor CSS Metrics [cssfamily] (done) | time=50ms [2021-04-01 22:12:22] INFO: Sensor CSS Rules [cssfamily] [2021-04-01 22:12:23] INFO: 12 source files to be analyzed [2021-04-01 22:12:23] INFO: 12/12 source files have been analyzed [2021-04-01 22:12:23] INFO: Sensor CSS Rules [cssfamily] (done) | time=1292ms [2021-04-01 22:12:23] INFO: Sensor JaCoCo XML Report Importer [jacoco] [2021-04-01 22:12:23] INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml [2021-04-01 22:12:23] INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer [2021-04-01 22:12:23] INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms [2021-04-01 22:12:23] INFO: Sensor JavaScript analysis [javascript] [2021-04-01 22:12:26] INFO: 13 source files to be analyzed [2021-04-01 22:12:28] INFO: 13/13 source files have been analyzed [2021-04-01 22:12:28] INFO: Sensor JavaScript analysis [javascript] (done) | time=4827ms [2021-04-01 22:12:28] INFO: Sensor C# Project Type Information [csharp] [2021-04-01 22:12:28] INFO: Sensor C# Project Type Information [csharp] (done) | time=1ms [2021-04-01 22:12:28] INFO: Sensor C# Properties [csharp] [2021-04-01 22:12:28] INFO: Sensor C# Properties [csharp] (done) | time=0ms [2021-04-01 22:12:28] INFO: Sensor JavaXmlSensor [java] [2021-04-01 22:12:28] INFO: Sensor JavaXmlSensor [java] (done) | time=1ms [2021-04-01 22:12:28] INFO: Sensor HTML [web] [2021-04-01 22:12:28] INFO: Sensor HTML [web] (done) | time=151ms [2021-04-01 22:12:28] INFO: Sensor VB.NET Project Type Information [vbnet] [2021-04-01 22:12:28] INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms [2021-04-01 22:12:28] INFO: Sensor VB.NET Properties [vbnet] [2021-04-01 22:12:28] INFO: Sensor VB.NET Properties [vbnet] (done) | time=1ms [2021-04-01 22:12:28] INFO: ------------- Run sensors on project [2021-04-01 22:12:28] INFO: Sensor Zero Coverage Sensor [2021-04-01 22:12:28] INFO: Sensor Zero Coverage Sensor (done) | time=20ms [2021-04-01 22:12:28] INFO: SCM Publisher SCM provider for this project is: git [2021-04-01 22:12:28] INFO: SCM Publisher 25 source files to be analyzed [2021-04-01 22:12:29] INFO: SCM Publisher 25/25 source files have been analyzed (done) | time=223ms [2021-04-01 22:12:29] INFO: CPD Executor 5 files had no CPD blocks [2021-04-01 22:12:29] INFO: CPD Executor Calculating CPD for 15 files [2021-04-01 22:12:29] INFO: CPD Executor CPD calculation finished (done) | time=49ms [2021-04-01 22:12:29] INFO: Analysis report generated in 165ms, dir size=202 KB [2021-04-01 22:12:29] INFO: Analysis report compressed in 86ms, zip size=78 KB [2021-04-01 22:12:30] INFO: Analysis report uploaded in 599ms [2021-04-01 22:12:30] INFO: ANALYSIS SUCCESSFUL, you can browse http://server123.mycorp.com:9000/dashboard?id=qa-dev_project1_1.Sonar_8_8_sonar_scanner [2021-04-01 22:12:30] INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report [2021-04-01 22:12:30] INFO: More about the report processing at http://server123.mycorp.com:9000/api/ce/task?id=AXiPfrh9RniEjxk9KTc9 [2021-04-01 22:12:40] INFO: Analysis total time: 32.061 s