This is the fifth day of my participation in Gwen Challenge
background
Since THERE was no application server before, I set up my own SonarQube service to run the quality test under my Window computer. The problem was that my computer was shut down, and my team mates could not use it. Now I have applied for a Linux server, and I can rebuild my own one. Update SonarQube to the latest version by the way.
What problem does SonarQube solve
SonarQube is an open source code quality analysis platform that makes it easy to manage code quality, check for bugs and potential logic problems, score code quality, health, and more. And provides a rich plug-in, support a variety of language detection, such as Java, Javascript, Python, C#, and other programming languages detection.
I. Environment configuration
- Linux system
- JDK 11
- SonarQube 8.8.0
- PostgreSQL
Install the JDK
Since SonarQube7.9 and above requires JDK11 to start, we must install JDK11.
(1) Download JDK
// Install data/ openJDK in the root directory
// Problem encountered: unable to establish SSL connection
wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz
// Bypass user authentication download
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz
Copy the code
(2) Decompress the JDK
/ / the JDK
tar -zxvf openjdk-11+28_linux-x64_bin.tar.gz
Copy the code
(3) Configure environment variables
// Edit the profile file in etc
vim /etc/profile
Add the following content to the /etc/profile file
export JAVA_HOME=/data/openjdk/jdk-11
export PATH=$JAVA_HOME/bin:$PATH
// Refresh environment variables
source /etc/profile
Copy the code
(4) Check whether the JDK is installed successfully
$ java -version
Copy the code
Install SonarQube
Download, decompress and install. The installation path I put in the data directory:
Download SonarQube
wget https:/ / binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.8.0.42792.zip
Copy the code
(2) Decompress SonarQube
uzip sonarqube-8.31.34397..zip
Copy the code
(3) Start the service
/ / into the bin of the installation path CD/data/sonarqube/sonarqube - 8.8.0.42792 / bin/Linux - x86-64. / sonar. Sh startCopy the code
Successful installation is shown as follows:
(4) Check whether the startup is successful
If you find problems with startup, you can use console to view exception logs
/ / into the bin of the installation path CD/data/sonarqube/sonarqube - 8.8.0.42792 / bin/Linux - x86-64. / sonar. Sh the consoleCopy the code
Four, SonarQube use
Service startup success, Sonarqube access address, generally is the IP address + port number 9000, http://172.28.206.100:9000, for example, page default is English, You can go to Configuration > App Market > Search Chinese Pack (Language Pack for Chinese) to install, and then restart, you can achieve Chinese.
V. Jenkins is used in conjunction with the project
Configure the relevant information before using:
- (1) SonarQube Scanner and Git plugin installation.
Go to Manage Jenkins > Manage Pulgins > Optional plug-ins > Enter SonarQube Scanner and Git plugin to install.
- Configure SonarQube Servers.
Go to Manage Jenkins > Manage System > SonarQube Servers and configure as follows:
- (3) Configure Git.
Go to Manage Jenkins > Global Tool Configuration and configure the Git name and path. You can view the installation path with whereis git.
- (4) Configure SonarQube Scanner.
Go to Manage Jenkins > Global Tool Configuration.
- (5) Add a project task.
Home > New Item > Create a New Task > Enter your task name > OK
- (6) Configure the code address and credentials.
Create your own new project > source management, build project configuration Gitlab address and SSH private key.
- (7) Configure Analysis Properties.
In the new project > Build, configure SonarQube Scanner’s Analysis Properties.
Sonar.sources=.sonar. SourceEncoding = utF-8 sonar. ProjectName =${name} sonar. sonar.login=admin sonar.password=123456Copy the code
- (8) Construction project.
Enter the project name and the corresponding branch and click Start Build.
- (9) Check code quality.
Once the build is complete, you can go to SonarQube to see the quality of your code.
6. Problems encountered
Problem a:
Elasticsearch can not run as root elasticSearch can not run as root elasticSearch cannot be started as user root.
$su - Sonarqube $su - SonarqubeCopy the code
Problem two:
Cannot write Elasticsearch yML Settings file because the new user does not have read and write permission for Sonarqube.
$chmod -r 777 Sonarqube / $chmod -r 777 Sonarqube /Copy the code
Question 3:
Fatal: Could not read from remote repository.Please make sure you have the correct access rights.
You can go to Manage Jenkins > Manage Credentials > Global Credentials to fix this problem.
Seven, finally
Sonarqube can only be used in test scenarios. The embedded database cannot be expanded, cannot be upgraded to a new version of Sonarqube, and does not support migrating your data to another database engine. We’ll solve this problem in the next video.
Eight, reference
- Sonarqube official documentation
- Set up SonarQube at window