In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Code quality Management of continuous Integration-Sonar [3]
Sonar introduction
Sonar is an open platform for code quality management. Through the plug-in mechanism, Sonar can integrate different testers
Tools, and continuous integration tools. Unlike continuous integration tools such as Hudson/Jenkins, Sonar
Instead of simply displaying the results of different code review tools (such as FindBugs, PMD, etc.) directly on the Web page,
These results are reprocessed by different plug-ins, and the changes in code quality are measured in a quantitative way.
Conveniently carry out code quality management for different sizes and types of projects.
In terms of support for other tools, Sonar not only provides support for IDE, but also on Eclipse and IntelliJ
IDEA shows the results online in these tools; at the same time, Sonar also provides interface support for a large number of continuous integration tools.
Use Sonar conveniently in continuous integration.
In addition, Sonar plug-ins can also provide support for programming languages other than Java, internationalization and reporting documentation
There is also good support.
Sonar deployment
Downloads and documentation for Sonar can be found at the following link: http://www.sonarqube.org/downloads/.
It should be noted that the latest version of Sonar requires at least JDK 1.8 or above.
In the last article, we have successfully used git to pull and pull, and the function of Sonar is to check whether the code has BUG. Except
Check whether the code has bug and other functions, such as: what is your code comment rate, code has some suggestions, writing language
The suggestion of the law. So we call it quality management.
Sonar can also grade the code and cite technocratic features (telling you there are a lot of things that haven't changed)
Sonar deployment
89 cd / usr/src/sonar 90 rz upload required software packages We upload them to the server via wget or download and rz
# Software package download: https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.6.zip
95 unzip sonarqube-5.6.zip decompression package 96 mv sonarqube-5.6 / usr/local/sonarqube 97 cd / usr/local/sonarqube/98 ln-s / usr/local/sonarqube/bin/linux-x86-64/sonar.sh / usr/local/bin/ link command directory
Prepare the Sonar database
If there is no database, execute yum install-y mariadb mariadb-server
102cd / usr/src/ MySQl5.7RPM 103rz upload required rpm package 105cd MySQl5.7RPM/ 107ls
108 yum-y localinstall mysql-community-* installs the MySQL package of this directory 109 systemctl start mysqld opens mysql 100 systemctl enable mariadb setting boot self
Log in to the database and operate
110 mysqladmin-u root password 123Settingthe MySQL database password
You can see there's a problem here. Resolve:
111 grep password / var/log/mysqld.log
What is in the red box is the password
112 mysql-u root-pamphyq% 9XsyEpurrystg' login database
Alter user 'root'@'localhost' identified by' 123.com'
Alter user 'root'@'localhost' identified by' Xgp@123.com'
Create database sonar character set utf8 collate utf8_general_ci; create database grant all on sonar.* to 'sonar'@'%' identified by' Sonar@123.com'; setup authorized user grant all on sonar.* to 'sonar'@'localhost' identified by' Sonar@123.com'; set authorized user configuration Sonar 113cd / usr/local/sonarqube/bin/ 115 ls
116ln-s / usr/local/sonarqube/bin/linux-x86-64/sonar.sh / usr/local/bin/ link commands directory 117vim conf/sonar.properties modify sonar configuration file sonar.jdbc.username=sonar # 14 username sonar.jdbc.password=Sonar@123.com # 15 password sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance # 23 to comment sonar.web.host=0.0. 0.0 # 99 to comment sonar.web.port=9000 # 106 to comment
Configure Java access database driver (optional)
By default, Sonar has its own embedded database, so if you use an Oracle database, you must manually copy the driver class to the ${SONAR_HOME} / extensions/jdbc-driver/oracle/ directory. Other supported databases provide drivers by default. For configuration of other databases, please refer to the official documentation:
Http://docs.sonarqube.org/display/HOME/SonarQube+Platform
Start Sonar and view the port
You can configure the IP address and port for Sonar Web listening in the Sonar configuration file, which defaults to port 9000.
118 sonar.sh start start sonar
119 netstat-anpt | grep 9000 View Port
120 tailf / usr/local/sonarqube/logs/sonar.log View sonar Log
# Port is 9000!
Web login: IP:9000
Tip:
Similar to jenkins, sonar is also plug-in-based.
There are two ways to install plug-ins in sonar: the first way is to download the plug-ins and store them in the sonar plug-in directory, and the second way is to use the web interface to install and store plug-ins [/ usr/local/sonarqube/extensions/plugins/]
Install Chinese plug-in
Login: user name: admin password: admin
Sonar installs' Chinese 'and php plug-ins
132 cd / usr/local/sonarqube/extensions/plugins/ enter the sonar host directory 133cp / usr/src/sonar/sonar-l10n-zh-plugin-1.11.jar. / copy the Chinese plug-in to the sonar directory 134cp / usr/src/sonar/sonar-php-plugin-2.9-RC1.jar. / copy the php plug-in to the sonar directory requires a restart to take effect 134sonar.sh restart Restart sonar 135 netstat-anpt | grep 9000 to view the port
After taking effect, the figure is as follows:
Download the scanner plug-in 140cd / usr/src/sonar/ into the directory where you just uploaded the sonar package 141unzip sonar-scanner-cli-3.3.0.1492-linux.zip extract scan plug-in 142mv sonar-scanner-3.3.0.1492-linux/ / usr/local/sonar-scanner move the extracted files to the sonar host directory 143cd / usr/local/sonar-scanner/ and enter the sonar host directory 145ln-s / usr/local/sonar-scanner/bin/sonar-scanner / usr/local/bin/ link command directory 146ln-s / usr/local/sonar-scanner/bin/sonar-scanner / usr/bin/ link command directory
We need to associate the scanner with the sonar.
143cd / usr/local/sonar-scanner/144 vim conf/sonar-scanner.properties modify sonar configuration file sonar.host.url= http://localhost:9000 # to comment sonar address sonar.sourceEncoding=UTF-8 # 8 to comment character set the following four lines come from / usr/ldocal/sonarqube/conf/sonar.properties sonar.jdbc.username=sonar # database account sonar.jdbc.password=Sonar@123.com # database password sonar.jdbc.url=jdbc:mysql:// Localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance # Database connection address # just open the comment
We now need to find a code for analysis.
The sonar plug-in provides a library of code
Github: https://github.com/SonarSource/sonar-examples
We download the package: https://github.com/SonarSource/sonar-examples/archive/master.zip
Decompression
150 unzip testalyzer-master.zip decompress the test file
151cd / usr/src/sonar/testalyzer-master/projects/languages/php/php-sonar-runner-unit-tests enters the test file
163The sonar-scanner test code file
Tip: without specifying anything, we will scan the sonar-project.properties file in the face directory and scan the file according to the configuration file. After the scan, we can see the scan results of the code on the web interface. The name here, the version is defined in the sonar-project.properties file.
The quality threshold helps us to set a threshold. If we exceed the corresponding threshold, we will have bug.
Test the second file
Cd / usr/src/sonar/testalyzer-master/projects/languages/javascript/javascript-sonar-runner
Sonar-scanner test
In order for jenkins to execute sonar when building the project, we need to install plug-ins on jenkins
You can now configure to combine jenkins and sonar. So that when we build the project, we do code testing.
Http://192.168.1.40:8081/ jdk installs the plug-in SonarQube Scanner. Gerrit Tr igge needs one by one.
After installation: you can now configure to combine jenkins and sonar. So that when we build the project, we do code testing.
System management-system settings-add sonarqube server---name randomly write the path of url sonarqube http://192.168.1.40: 9000
Click Save
System management-Global tool configuration-add SonarQube Scanner--- and uncheck automatic installation-name write freely-SONAR_RUNNER_HOME / usr/local/sonar- scanner
Configuration
Configure the web- demo project of the last lesson-build-Execute SonarQube Scanner-Analysis properties content in cat / usr/src/sonar/testalyzer-master/projects/languages/php/php-sonar-runner-unit-tests/sonar-project.properties (everyone's installation directory is different)
Edit our project and choose the most decentralized. Find the build
Cat / usr/src/sonar/testalyzer-master/projects/languages/php/php-sonar-runner-unit-tests/sonar-project.properties
After filling in, we click Save.
217 cd / usr/src/sonar/testalyzer-master/projects/languages/php/php-sonar-runner-unit-tests 219 cp-r * / root/xgp-demo/ 220 cd / root/xgp-demo/ enter xgp project 221 git add * upload to cache 222git commit-m "sonar" upload to board library 223 git push origin master upload to remote library Tip: the SonarQube cannot be clicked at this time
Browser JDK View
Click Console Output to view the contents of the build output
# Tip: as long as there is no error
Gielab views and modifies names
Modify it again and change the key.
Check that a xgpa has been added on sonar
Jenkins email Alert
Log in to QQ Mail to get the authorization code
1. POPE3/SMTP service needs to be enabled.
2. For the password configured on jenkins, we need to click generate authorization code to use it.
Back to jdk
System management-system settings-Jenkins Location---- system administrator email address
-email notification-SMTP server smtp. QQ。 Com
-user default email suffix @ qq. Com
-check to use smtp authentication
Username password (generated authorization code)
-check to use ssl
-smtp port 465
-check to test the configuration by sending a test email
Configure web- demo project-post-build operation-add E-mail Notification---Recipient recipient address
-Editable Email Notification---Project From fill in the project name-Project Recipient Lis t recipient email address-
Triggers---add Triggers----always-- Send To retains only Recipient List
Failed mail
Test: turn off git (failed messages)
Gitlab-ctl stop
Successful email
Testing: successful messa
Start gitlab-ctl start
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.