...
Pseudo name | Description |
---|---|
BRANCH_NAME | Name of branch under consideration. Can optionally be used in combination with PATH_OF_REPOSITORY |
PATH_OF_REPOSITORY | Pathname to your Git project (Github, BitBucket, etc) |
SQ_SCANNER_INSTALL_DIR | This name refers to the local installation directory of the scanner for SonarQube |
SQ_PROJECT_LOCAL_INSTALL_DIR | This name refers to the local installation directory of your project on your cumputer |
SONARQUBE_TOKEN | Your SonarQube token. This is usually created when a project is entered into SonarQube but can also be newly requested if needed. |
Clone your Bitbucket repository
First you need to clone the Bitbucket repository to your local machine.
Clone your project repository
1 |
|
Prepare the SonarQube scanner
The following steps are nesessary to prepare the SonarQube scanner.
Install the SonarQube scanner
To install the scanner on your machine please follow instructions here.
When installed, the SonarQube scanner usually resides in a directory on your local machine. The installation directory of the scanner is usually different from the installation location of the development project. We will be referring to the installation directory of the scanner as SQ_SCANNER_INSTALL_DIR.
Create a token in SonarQube (optional step)
This step can be omitted when you have already created and SAVED your SonarQube token. If you have not done it before or if you have forgotten your SonarQube token, please follow the SonarQube description here for more info on generating tokens.
Remember your SonarQube token (now referred to as SONARQUBE_TOKEN). You will need it in the next step.
Edit the sonar-scanner.properties file
There is a variety of options, all of which serve to adjust your SonarQube scanner to your environment. These adjustments must be done in the file sonar-scanner.properties which can be found within the <SQ_SCANNER_INSTALL_DIR>/conf directory.
...
1 |
|
Add the SonarQube scanner to you PATH variable
Add the executable directory of the SonarQube scanner (<SQ_SCANNER_INSTALL_DIR>/bin) to your PATH environment variable. Typical installation directories are:
...
1 |
|
Configuration file sonar-project.properties
Then, in order to run the scanner on a specific project, you need to do the following:
...
1 |
|
Analyse your project
Run the SonarQube scanner
Now that you have the set up and files configured properly, all you need to do is to run the sonar-scanner from within the project's directory.
The command line should eventually show "EXECUTION SUCCESS", as depicted below:
View your project in SonarQube
That's all. Now you can go to the SonarQube web interface to view the results of the analysis:
SonarQube Analysis
A typical SonarQube analysis will include
...
You can click on the results and you will be redirected to the project issues section on SonarQube website
Summary
SonarQube is a powerful platform for continuous inspection of source code and various aspects pertaining to quality and best practices. Integrating SonarQube analysis into pull requests in Bitbucket server makes this very useful for developers. SonarQube's website has more information on the product.
...