jenkins + sonar build process

A First Configuration JDK
In the / etc added to the end of the profile / environment variable :( command vim / etc / profile open editing environment variable )
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_11
export JRE_HOME=/usr/lib/jvm/jdk1.8.0_11/jre 
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
The above is my ubuntu JDK address , reload the Source  / etc / Profile, take a look at whether the configuration jdk -version with the Java , a novice at random Baidu how to install JDK.

II. Configuring maven
1. Download good maven to extract the appropriate path, I have here is put under / usr / lib / maven, modify under local repository address, configure the environment variables.


2. mvn -v to check whether maven configured,


III. Configuration sonar
1. Download good sonarqube-4.5.zip, to extract the respective paths, edit vim sonarqube-4.5 / conf / sonar.properties, configure the connection information database, as shown below:


2. Add the database connection information in maven setting.xml:

3. Create a database sonar in mysql
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 ;  

4. 启动sonar



试下 http://localhost:9000 是否能成功,成功会出现下面页面:


四. 用eclipse集成sonar检查代码
1.下载eclipse sonar插件

2.测试sonar 服务器, http://IP:9000 (我这里测试没有设置相应的sonar权限,如果有设置权限加上账号密码就行),Test connection



3.在我们项目加上sonar-project.properties,可以参考: http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Runner



我们可以再eclipse run configurations 上运行 (也可以切换到项目所在路径运行:   mvn sonar:sonar  )

出现下图表示成功:
 


五.集成jenkins
1. 我们这里用到sonar_runner
配置好sonar_runner 加入环境变量/etc/profile



重新source /etc/profile 之后检查,sonar-runner -h是否生效,如下图:



3. Start jenkins (can also be placed under tomcat start):
java -jar jenkins.war

4. Check  http: // IP: 8080 Launch OK (I have used jenkins, set up after the success of the writing process, you might start with me a little bit different chart below)





5. System Management added sonar plugin 






6. System Configuration


7. Create a new job

8. The actual fill SVN address, adding JDK etc., and then select the sonar analysis based on


9. Fill Project properties (  If you do not fill in Project properties will load the project path sonar-project.properties)


10. Run (SONAR not need to check the success code can be packaged)







Reproduced in: https: //my.oschina.net/kaishui/blog/371528

Guess you like

Origin blog.csdn.net/weixin_33713350/article/details/91900312