jenkins + sonar 安装配置

最近把snoar 添加上了

 

[root@snoar data]#   wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.5.zip

[root@snoar data]#  unzip sonarqube-6.5

[root@snoar data]#  mv  sonarqube-6.5   sonarqube

修改配置文件

sonar.jdbc.username=fengjian
sonar.jdbc.password=fengjian123

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

sonar.web.javaOpts=-server -Xms256m -Xmx768m -XX:+HeapDumpOnOutOfMemoryError

sonar.web.host=0.0.0.0
sonar.web.context=/sonar
sonar.web.port=9000

 

启动sonar

[root@jenkins sonar]# /data/sonar/bin/linux-x86-64/sonar.sh start

查看日志 

[root@jenkins sonar]# tail -f /data/sonar/logs/sonar.log

 

登录snoar页面,默认admin, admin

http://172.16.230.171:9000/sonar , chinese 是中文反义

 

 

jenkins 安装插件

SonarQube Plugin

jenkins 设置全变配置 ,  token 在 sonar 个人管理中能看到。

 

 

安装sonar scanner

 

 

 

 

 

修改mavn 配置文件 setting.xml

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
  <localRepository>/data/repository</localRepository> 

  <pluginGroups>
 
  </pluginGroups>

  <proxies>

  </proxies>

  <servers>
 
    <!-- 授权配置 -->
    <server>
        <id>releases</id>
        <username>admin</username>
        <password>wwxxaadd</password>
    </server>
    <server>
        <id>snapshots</id>
        <username>admin</username>
        <password>wwxxaadd</password>
   </server>    

  </servers>

  <mirrors>

     <!-- 镜像配置:覆盖中央仓库默认地址 -->
    <mirror>   
          <id>central</id>   
          <mirrorOf>*</mirrorOf>   
          <url>http://172.16.230.111:8081/nexus/content/groups/public/</url>   
    </mirror>
  </mirrors>

  <profiles>
 
    <profile>  
      <id>dev</id>  
      
      <activation>  
        <activeByDefault>false</activeByDefault> 
        <jdk>1.7</jdk>  
      </activation>  
        
      <properties>  
        <maven.compiler.source>1.7</maven.compiler.source>  
        <maven.compiler.target>1.7</maven.compiler.target>  
        <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>  
      </properties>  
      
      <repositories>
        <repository>
          <id>nexus</id>
          <url>http://172.16.230.111:8081/nexus/content/groups/public</url>
          <releases>
            <enabled>true</enabled>
         </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
      </snapshots>
        </repository>
      </repositories>
      
      <pluginRepositories>
        <pluginRepository>
          <id>nexus</id>
          <url>http://172.16.230.111:8081/nexus/content/groups/public</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>      
        </pluginRepository>      
      </pluginRepositories>      
    </profile>

<!-- 添加的sonar 配置部分 --> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <!-- database--> <sonar.jdbc.url>jdbc:mysql://172.16.230.173:3306/sonar</sonar.jdbc.url> <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver> <sonar.jdbc.username>fengjian</sonar.jdbc.username> <sonar.jdbc.password>fengjian123</sonar.jdbc.password> <!-- Optional URL to server. Default value is http://localhost:9000 --> <sonar.host.url>http://172.16.230.171:9000/sonar</sonar.host.url> </properties> </profile> </profiles> <!-- 激活配置 --> <activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles> </settings>

 

 

在maven编译时,后面加上sonar:sonar参数就OK了。比如:

clean install -Dmaven.test.skip=true sonar:sonar

 

posted @ 2017-09-29 16:04  fengjian1585  阅读(852)  评论(0编辑  收藏  举报