Directory
1, Simple introduction principle
2, Sonar environment configuration
3, Sonar-runner Environment configuration
4, the integration of the implementation of the production of visual report 1, Introduction principle
I mentioned that my previous oclint was performed on several MAC slave configured by Jenkins, and the Oclint generated report was PMD format, which was parsed and demonstrated through Jenkins's plug-in pbulish PMD analysis.
But when the development wants to see which issue, will be very troublesome, is not very intuitive, needs to click to Jenkins job inside to look for. In order to facilitate the development of small partners, access to information to know the sonar.
Online sonar has a very detailed introduction, I do not repeat, I understand the sonar is similar to the flask I wrote a server, can be used to store data and display data, sonar-runner similar to the requests of a POST request, It sends an XML file that Oclint checks the generated PMD format to sonar, and then sonar the received data into
MySQL or other types of databases, and show.
For Jenkins-triggered jobs, I'm triggering a job execution when developing change-merge to the development branch through the Gerrit trigger mechanism in Jenkins. 2, Sonar environment configuration
Sonar environment configuration is divided into two steps, sonar and MySQL.
"1" sonar
Here I try to build sonar in both Mac and Linux environments.
Sonar download address is: https://www.sonarqube.org/downloads/
After the download is good, is a. tgz compressed file, after decompression, here Linux and MAC configuration environment is consistent no different, put in any folder location can be. Add the/opt/sonar/below.
The Start Sonar Service command is:
# # Linux boot
./bin/linux-x86-4/sonar.sh start
# mac boot
./bin/macosx-universal-64/sonar.sh start
Before I started, I changed conf/sonar.properties because I started a few flask services on Linux that already took up a lot of ports.
I have changed these items:
sonar.web.host=0.0.0.0
sonar.web.port=9007
sonar.search.port=9011
Then execute the start command separately, open http://127.0.0.1:9007, you can enter the sonar interface normally. But at the bottom there is the red word hint because there is no connection to the database.
Here I change sonar.search.port because, I found that the default port 9001 has been occupied, the service does not start up, the error prompts in the Logs/ce.log see.
"2" MySQL
Mac and Linux are slightly different here.
Install Command:
# # Linux I recommend the RPM format installation, and install MySQL 5.7 version
1, https://dev.mysql.com/downloads/repo/apt/download Dev package
2, Dump Linux, and then execute
sudo dpkg-i mysql-apt-config_0.8.3-1_all.deb
groupadd mysql
useradd-r-g MySQL
mysql sudo apt-get install l Ibaio-dev
# mac installs MySQL
brew install MySQL
When MySQL is installed, start the command:
# # Linux
sudo/etc/init.d/mysql start
# mac
mysql.server start
Log on Mysql,mysql-uroot-proot By default root user, after login.
Additional sonar database and sonar users are required.
CREATE DATABASE sonar CHARACTER SET UTF8 COLLATE utf8_general_ci;
CREATE USER ' sonar ' identified by ' sonar ';
GRANT all on sonar.* to ' sonar ' @ '% ' identified by ' sonar ';
GRANT all on sonar.* to ' sonar ' @ ' localhost ' identified by ' sonar ';
FLUSH privileges;
After the success, restart the MySQL service.
Change the configuration of the Conf/sonar.properties database for it to take effect.
Sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar? Useunicode=true&characterencoding=utf8&rewritebatchedstatements=true&useconfigs=maxperformance
Restart the sonar service again, and then log on again http://127.0.0.1:9007, normal boot, you can see the bottom of the page of the red Word warning has not been, in fact, can also be logs folder under the Log view.
Tips, here's why I emphasize using the MySQL 5.7 version because the first time I install under Linux is with sudo apt-get install mysql-server, resulting in a 5.5 version of the installation, and Sonar 6.2 mismatch. 3, Sonar-runner configuration
Sonar-runner is similar to a request-issuing command, which should be placed on the Mac slave of the execution oclint.
Sonar-runner Download Path: http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
After decompression, the environment variable configuration is not configured, I suggest not to configure Bash_profile, because to make the bash_profile effective, Jenkins need to disconnect with slave and then heavy connection, in order to take effect. This is unreasonable for the continuous integration of cluster services.
To make Sonar-runner work, you need to configure Sonar-runner/conf/sonar-runner.properties
sonar.host.url=http://localhost:9007
sonar.sourceencoding=utf-8
sonar.login=admin
sonar.password= Admin
This time need to verify in the command line, assuming Sonar-runner placed in OPT, opt/sonar-runner/bin/sonar-runner, hint:
Sonarqube Runner 2.4
Java 1.8.0_111 Oracle Corporation (64-bit)
Mac OS X 10.12.3 x86_64 info:runner Configura
tion file:/users/huami/opt/sonar-runner/conf/sonar-runner.properties
info:project Configuration File:none
info:default locale: "ZH_CN", Source code encoding: "UTF-8"
Description Sonar-runner has been configured well. 4, the integration of the implementation of the production of visual reports
"1" You need to load an OC check jar bundle plug-in under the server sonar/extensions/plugins/before performing Sonar-runner.
Sonar-objective-c-plugin-0.5.0-snapshot.jar plugin Download Address: Https://github.com/ChenTF/iOS-sonarShell
After you have downloaded it, dump it to sonar/extensions/plugins/and restart the sonar service.
"2" needs to create a new build or inside the downloaded package, put sonar-project.properties into the iOS Project home directory, and finally my sonar-project.properties is:
########################## # Required Configuration # ########################## Sonar.projectkey=mifit
Sonar.projectname=mifit sonar.projectversion=1.0 Sonar.language=objectivec # Project Description Sonar.projectdescription=fake Description # Path to source directories project file directory Sonar.sources=mifit # Xcode project Config Uration (. xcodeproj or. xcworkspace) #-> If you have a project:configure ' only Sonar.objectivec.project #-> if Have a workspace:configure sonar.objectivec.workspace and Sonar.objectivec.project # and use the later to specify which
Project (s) to include into the analysis (comma separated list) sonar.objectivec.project=mifit.xcodeproj Sonar.objectivec.workspace=mifit.xcworkspace # Scheme to build your application Sonar.objectivec.appscheme=mifit # Scheme to builds and run your tests (comment following line for you don ' t have any tests) ########################## # OPT ional configuration # ########################## # Encoding of the source code SONAR.SOURCEencoding=utf-8 Sonar.objectivec.oclint.reportpath=lint.xml Sonar.scm.enabled=false sonar.host.url=http://x.x.x.x
: 9007
Everything is ready, only the east wind.
"3" I have generated the lint.xml of PMD format after oclint execution in the iOS project directory.
In order to verify the sonar built without problems, direct CD to the project root directory to perform sonar-runner send lint.xml result information to sonar service.
If the previous configuration is normal, then execute sonar-runner,log if this is the case
Analysis of the uploaded in 2489ms 11:47:24.701 info-analysis successful, can browse http://x.x.x.x:9007/dashboard/ Index/mifit 11:47:24.702 info-note that you'll be able to access the updated dashboard the once the server has processed The submitted analysis 11:47:24.702 Info-more about the "processing at http://x.x.x.x:9007/api/ce/task?id= AVRK7MT-YTB445TPRSN7 11:47:25.577 info-task Total time:24.425 s INFO:----------------------------------------------- -------------------------info:execution SUCCESS INFO:----------------------------------------------------------- -------------Total time:32.521s Final memory:23m/777m
You can go to http://192.168.1.101:9007 to see if the record of project execution has been uploaded correctly.
I did not join the definition of their own rules, that is the static code monitoring platform The most important place, and so I practice good, and then share it, I now just to configure the environment.
Write a bad place, please more correct.