`

SonarQube和Jenkins的集成

阅读更多

原文:http://itindex.net/detail/55522-sonarqube-jenkins?utm_source=tuicool&utm_medium=referral (SonarQube和Jenkins的集成)

 

http://my.oschina.net/jiangbianwanghai/blog/478338?p=1 (SonarQube代码质量管理平台安装与配置)

http://www.cnblogs.com/zhuhongbao/p/4197974.html (配置sonar、jenkins进行持续审查)

http://blog.csdn.net/hunterno4/article/details/11687269 (SonarQube代码质量管理平台安装与使用) 

 

1、安装sonarqube

      1)、将下载的http://downloads.sonarsource.com/sonarqube/sonarqube-5.1.1.zip解压后放到/opt目录下。具体步骤如下:

[root@localhost home]# wget -c http://downloads.sonarsource.com/sonarqube/sonarqube-5.1.1.zip

[root@localhost home]# unzip sonarqube-5.1.1.zip

[root@localhost home]# mv sonarqube-5.1.1 /opt/

 

       2)、配置环境变量,并让其立即生效

[root@localhost opt]# vim /etc/profile

      export SONAR_HOME=/opt/sonarqube-5.1.1

[root@localhost opt]# source /etc/profile

       

       3)、配置sonar.properties

 [root@localhost opt]# cd sonarqube-5.1.1/conf/

[root@localhost conf]# ll

total 20

-rw-r--r--. 1 root root 13865 Jun  6 17:33 sonar.properties

-rw-r--r--. 1 root root  3288 Jun  2  2015 wrapper.conf

[root@localhost conf]# vim sonar.properties

找到并根据自己配置修改相关内容,

sonar.jdbc.username=root

sonar.jdbc.password=chbigdata

sonar.jdbc.url=jdbc:mysql://172.17.123.137:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

sonar.jdbc.maxActive=25

sonar.jdbc.maxIdle=5

sonar.jdbc.minIdle=2

sonar.jdbc.maxWait=5000

sonar.jdbc.minEvictableIdleTimeMillis=600000

sonar.jdbc.timeBetweenEvictionRunsMillis=30000

 

sonar.web.host=0.0.0.0

sonar.web.context=

sonar.web.port=9000

保存退出,

 

      4)、启动、停止、重启服务

[root@localhost sonarqube-5.1.1]# ./bin/linux-x86-64/sonar.sh start

Starting SonarQube...

Started SonarQube.

 

[root@localhost sonarqube-5.1.1]# ./bin/linux-x86-64/sonar.sh stop

Stopping SonarQube...

Stopped SonarQube.

 

[root@localhost sonarqube-5.1.1]# ./bin/linux-x86-64/sonar.sh restart

 

       5)、浏览器地址栏打开,http://172.17.123.137:9000/

      默认用户名,密码;admin/admin   登录后可以自己修改密码;

      并且sonarqube 登录后必须设置的地方是:


 

SonarQube默认是没有安装中文语言包的。可以看到我的截图显示的是中文,因为我安装了中文语言包。如何安装语言包呢。进入SonarQube插件目录,下载语言包即可。步骤如下:

[root@localhost sonarqube-5.1.1]# cd extensions/plugins/

[root@localhost plugins]# wget -c http://repo1.maven.org/maven2/org/codehaus/sonar-plugins/l10n/sonar-l10n-zh-plugin/1.8/sonar-l10n-zh-plugin-1.8.jar

 

       6)、sonarqube的插件配置管理

登录sonarqube后,配置---系统---更新中心



 这样就可以看到已经安装的插件,可以安装的插件,其实语言包也可以在这种方式安装;

点击:Avilable Plugins  就可以安装你想要的插件; 

 

2、安装sonarqube-runner 也就是(sonar-runner)

      1)、将下载的http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip解压后放到/opt/目录下。具体步骤如下:

[root@localhost home]# wget -c http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip

[root@localhost home]# unzip sonar-runner-dist-2.4.zip

[root@localhost home]# mv sonar-runner-2.4/ /opt/

 

       2)、配置环境变量,并让其立即生效

[root@localhost opt]# vim /etc/profile

export SONAR_RUNNER_HOME=/opt/sonar-runner-2.4/

export PATH=$PATH:$JAVA_HOME/bin:${ANT_HOME}/bin:${MAVEN_HOME}/bin:$SONAR_RUNNER_HOME/bin:$PATH

将bin路径添加到path路径中,并保存让其立即生效;

 

        3)、修改配置sonar-runner.properties

[root@localhost sonar-runner-2.4]# vim conf/sonar-runner.properties

 

sonar.host.url=http://172.17.123.137:9000

sonar.jdbc.url=jdbc:mysql://172.17.123.137:3306/sonar?useUnicode=true&characterEncoding=utf8

sonar.jdbc.username=root

sonar.jdbc.password=chbigdata

 

#----- Default source code encoding

sonar.sourceEncoding=UTF-8

#----- Security (when 'sonar.forceAuthentication' is set to 'true')

sonar.login=admin

sonar.password=chbigdata

 PS:刚才我们已经看到SonarQube已经可以访问了,所以就将sonar.host.url改成了实际的访问地址。

用以下命令验证sonar-runner 是否安装成功

[root@localhost home]# sonar-runner -h

INFO: 

INFO: usage: sonar-runner [options]

INFO: 

INFO: Options:

INFO:  -D,--define <arg>     Define property

INFO:  -e,--errors           Produce execution error messages

INFO:  -h,--help             Display help information

INFO:  -v,--version          Display version information

INFO:  -X,--debug            Produce execution debug output

 

 

        4)、运行sonar-runner分析源代码

必须从svn上下载源码,并在源码的根目录中新增一个配置文件:sonar-project.properties,内容如下:

# Required metadata

sonar.projectKey=lstvaftersales

sonar.projectName=lstvaftersales

sonar.projectVersion=1.0

# Comma-separated paths to directories with sources (required)

 

sonar.sources=src

完成后就可以直接运行

[root@localhost ls_shgj]# sonar-runner   就开始构建了 ,完了后登录sonarqube 查看

 

 

 

 3、下载jenkins的sonar插件,sonar.hpi 下载地址

      https://wiki.jenkins-ci.org/display/JENKINS/SonarQube+plugin ;

 下载后,登录jenkins系统,点击 系统管理--- 管理插件,高级 中上传下载的sonar.hpi 插件并重启jenkins 或者jenkins所在的容器;

下载插件,也可以在插件管理中种搜索相关的插件来下载;不建议在线安装,因为目前google的代理问题;



 

 成功安装sonarqube插件后可以看到

当你看到上边这个界面后,则可以配置sonarqube的插件配置了;



 

  完成后,再配置sonarqube-runner的安装路径;



 配置好后,再配置相关的构建任务中添加sonar构建;



 

 

 这些步骤完成后,可以将这个构建项目job让其立即构建

得在构建任务中可以查看控制台信息如下;

 



 

 

 

 

 

 

 

 

 

 

http://dl2.iteye.com/upload/attachment/0108/6118/6d4e5501-52bd-39ed-84f1-0d715c31d3fc.pdf (Sonar 实战·)

  • 大小: 88.2 KB
  • 大小: 85.9 KB
  • 大小: 58.9 KB
  • 大小: 66.4 KB
  • 大小: 66.2 KB
  • 大小: 31.5 KB
  • 大小: 74.3 KB
  • 大小: 41.7 KB
  • 大小: 79.9 KB
  • 大小: 132.3 KB
  • 大小: 46.5 KB
  • 大小: 68.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics