First, the documentation
This document is for illustrative Jenkins + tomcat + sonar + SVN integrated analysis code to build processes and related solutions to the problems and issues that may be encountered; this document for public internal staff, the process of building some of the work for remote access Jenkins, sonar and so, if you do not need to build a local server to do related work; Jenkins and sonar to build environment for Linux, mysql, jdk1.7, jenkins, sonar4.5 , etc., related to the release notes will be described in detail in subsequent documents.
Two, jdk1.7 installed
1, ready to jdk installation package
Go to the official website select the version you need to download the rpm package, http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ;
2, install jdk
( 1) installed rpm package, the command: rpm -ivh jdk-6u45-linux -amd64.rpm
( 2) Configuration JDK environment variables:
. A [the root Tools @ localhost] $ # Vim the HOME / .bash_profile
. B, add the following information:
#Java Profile <br>
export JAVA_HOME = / usr / java / jdk1.6.0_45 ( in accordance with their real directory)
Export the CLASSPATH =:. $ JAVA_HOME / jre / lib / rt.jar: $ JAVA_HOME / lib / dt.jar: $ JAVA_HOME / lib / Tools .jar
the PATH the PATH = $ Export: $ JAVA_HOME / bin
c save and exit;.
. d so that environmental variables : [the root @ localhost Tools] #source / etc / Profile
. e jdk detect whether the installation was successful : [root @ localhost Tools] # echo $ JAVA_HOME
/usr/java/jdk1.6.0_45 (display the contents of this line represents a successful installation)
Or : [root @ localhost Tools] # the Java -version
Enter the above command will display the next version of jdk represents a successful installation
Three, SONAR Installation and Configuration
1, installing sonar
( 1) Introduction Sonar
Sonar is a platform for open-source code quality management, quality management for Java source code. By plug-in mechanism, Sonar can integrate disparate testing tools , code analysis tools, as well as continuous integration tools, such as pmd-cpd, checkstyle, findbugs, Jenkins. Through different plug-ins on these results further processing, code quality metrics by quantifying changes in the way, so you can easily to different sizes and types of engineering code quality management.
Meanwhile Sonar also a large number of continuous integration tool provides an interface support, you can easily use in continuous integration Sonar.
In addition, Sonar plugin can also be other than the Java programming language support for international reporting and documentation is also good support.
( 2) Download Software: wget http://dist.sonar.codehaus.org/sonar-3.7.4.zip
( 3) decompression software: unzip sonar-3.7.4.zip
( 4) Configuration Database
Apache Derby is installed and the default database that comes with Sonar used, in addition to Sonar provides support for the following databases: MySQL 5.x, Oracle 10g XE, Postgresql, MS SqlServer and so on, this article describes how to configure an example mysql database:
Here you first need to configure the database information:
the premise is that you have the mysql database installation, will not be discussed here database installation;
登录数据库命令:mysql –uroot -p
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> grant all on sonar.* to sonar identified by 'sonar';
mysql> grant all on sonar.* to sonar@'192.168.5.105' identified by 'sonar';
mysql> flush privileges;
2, SONAR environment configuration
(1) modify the configuration file
[root@localhostdata]# vim home/dev/sonar-3.7.4/conf/sonar.properties
( Here, the folder conf file sonar installation path inside the sonar.properties)
modified following fields (that is, the configuration database information, no other action):
# User credentials.
# Permissions to create tables, indices and triggers must be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username=root
sonar.jdbc.password = 123456 (this is a link to the database user name and password)
#----- Embedded Database (default)
# It does not accept connections from remote hosts, so the
# server and the analyzers must be executed on the same host.
#sonar.jdbc.url=jdbc:h2:tcp://localhost:9092/sonar
# H2 embedded database server listening port, defaults to 9092
#sonar.embeddedDatabase.port=9092
#----- MySQL 5.x
sonar.jdbc.url=jdbc:mysql://192.168.5.105:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
(Note: sonar.jdbc.url = jdbc: mysql: // localhost: 3306 / sonar if remote deployment, address database link recommendations written as IP address, sometimes the system can not resolve localhost, in case of error)
# By default, ports will be used on all IP addresses associated with the server.
= 192.168.5.105 sonar.web.host ( the IP address)
# Web context. When set, it must start with forward slash (for example /sonarqube).
# The default value is root context (empty value).
= sonar.web.context / SONAR (the default is "/", can also be written as "/ sonar"; if it takes time, "/", when accessed using IP plus port number can be visited, if written as "/ sonar", visit later add the port number "/ sonar")
# TCP port for incoming HTTP connections. Disabled when value is -1.
sonar.web.port = 9001 (Access Port number)
( 2) Start sonar
Editing .bash_profile, adding environment variables SONAR_HOME
$ vi $HOME/.bash_profile
Modified to the following:
PATH=$PATH:$HOME/bin
SONAR_HOME=$HOME/sonar
drop out
export PATH SONAR_HOME
The environment variables to take effect
Source $HOME/.bash_profile
Run the following command to start sonar, sonar other operating systems offer a startup script
$ ${SONAR_HOME}/bin/linux-x86-64/sonar.sh start
Or bin / linux-x86-64 / the next ./ sonar.sh
Access in the browser : http: // localhost: 9001 / sonar ( context defaults to "/", the above configuration file modified to "/ sonar", to add "/ sonar" to access), run the interface is as follows:
Four, SONAR-Runner Installation and Configuration
1, SONAR - Runner Installation
sonar-runner is installed with the same sonar; to download the package, and then extract the installation package, add environmental variables
Editing .bash_profile, adding environment variables SONAR_HOME
$ vi $HOME/.bash_profile
Modified to the following:
PATH=$PATH:$HOME/bin
SONAR_RUNNER_HOME=$HOME/sonar-runner
drop out
export PATH SONAR_HOME
The environment variables to take effect
Source $HOME/.bash_profile
2, SONAR-configuration Runner
Modify sonar.host.url, sonar.jdbc.url, sonar.jdbc.username, sonar.jdbc.password, sonar login name and password, to modify the actual configuration of sonar
So far, sonar-runner installation is complete
Five, Jenkins installation
1, Jenkins deployment
jenkins.war file, placed directly under the Tomcat webapps directory, start Tomcat service;
Modify the configuration file server.xml in the tomcat
2, visit Jenkins
Access: http://127.0.0.1:8010/jenkins
You can view the following screen, Jenkins deployed
3, problems encountered and solutions
( 1) tomcat can not extract the files to deploy Jenkins Jenkins, because the tomcat's server.xml configuration file more [xmlValidation = "false" xmlNamespaceAware = " false ] these two configuration items, after deleting restart tomcat can solve the problem
(2)tomcat启动是,部署Jenkins时报错【SEVERE: Failed to initialize Jenkins hudson.util.AWTProblem: java.lang.InternalError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.】
Solution: The reason: because the use of graphics, the Java program to find the graphical interface on linux whether to start
Solution: do not let java linux graphical interface to find, when you start adding options in the java java -Djava.awt.headless = true
Implementation: If tomcat, modified to /tomcat/bin/catalina.sh in
JAVA_OPTS=-Djava.awt.headless=true
Six, Soanr integration with Jenkins
1, installing sonar jenkins plugin plugin
In selecting sonar jenkins plugin in the Plugin Manager Jenkins, the plug-in can all call each time to build sonar code metrics
Enter the page to sonar plug-in configuration, as shown below:
2, building project
Click New
Enter a project name:
Enter the SVN Address:
Svn address in Chinese, need to be configured as follows:
Increasing build configuration selected invoke standalone sonar analysis, and (note provided Encoding encoding, the encoding codes to be analyzed according to the formatting) configured as follows
Click Save to enter the main page, you can see the new project, click on the small arrow to the right of the project, click on the building immediately, that is, starting from the SVN to download the source code
Click the project operating results
Click the console output that is
To see the console print the results.
The application will automatically trigger when building Sonar inspection of the code, you can see the results by visiting sonar
3, problems encountered and solutions
Jenkins and sonar when you need to install an integrated plug-in, you can not install the plug-in can go inside the Plugin Manager [Jenkins] https://wiki.jenkins-ci.org/display/JENKINS/SonarQube+plugin download plug-ins, and then upload it to Jenkins Plugin Manager in on it