jekins配合sonar配置

What ?

Sonar是一个用于代码质量管理的开源平台

Why ?

Where?

https://www.sonarqube.org/

How?

sonar安装

下载

useradd sonar
passwd sonar
cd /opt/soft/
wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.6.4.zip
unzip sonarqube-5.6.4.zip
vi $HOME/.bash_profile

修改如下

1
2
3
PATH=$PATH:$HOME/bin
SONAR_HOME=/opt/soft/sonarqube-5.6.4
export PATH SONAR_HOME
1
yum install postgresql
1
2
3
4
mysql> CREATE USER 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> create database sonar;
mysql> grant all privileges on sonar.* to 'sonar'@'%' identified by 'sonar';
mysql> flush privileges;

编辑${SONAR_HOME}/conf/sonar.properties配置数据库

1
2
3
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

启动

${SONAR_HOME}/bin/linux-x86-64/sonar.sh start

在浏览器中访问

http://localhost:9000/

修改默认端口为 9009 ,否则和 hdfs冲突

vi ${SONAR_HOME}/conf/sonar.properties
sonar.web.port=9009
{SONAR_HOME}/bin/linux-x86-64/sonar.sh restart

插件

sonarqube scanner
https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.5.1.zip

jekins安装

下载

useradd jekins
passwd jekins
cd /opt/soft/

1
2
3
4
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key`
yum install jenkins
service jenkins start

登录及初始化

http://ip:8080/jenkins
第一次安装jenkins的时候,会提示你要求输入安装密码,
cat /var/lib/jenkins/secrets/initialAdminPassword
按照提示将密码粘贴到对应的输入狂即可

修改默认端口

vi /etc/sysconfig/jenkins

1
JENKINS_PORT="8084"

service jenkins start


选择 sonar 插件,安装重启

maven安装

  • 跳转到软件目录
    cd /opt/soft
  • 下载
    wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
    tar zxvf apache-maven-3.3.9-bin.tar.gz
  • 修改环境变量
    vi ~/.bash_profile
1
2
export M2_HOME=/opt/soft/apache-maven-3.3.9
export PATH=$PATH:$M2_HOME/bin
  • 使生效
    source ~/.bash_profile
  • 验证是否成功
    mvn -version

git安装

  • 安装依赖
    yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
    yum install gcc perl-ExtUtils-MakeMaker
  • 下载源码
    wget https://github.com/git/git/archive/v2.5.0.tar.gz
  • 解压

    1
    2
    tar zxvf v2.5.0.tar.gz
    cd git-2.5.0/
  • 编译安装

    1
    2
    make prefix=/usr/local/git all
    make prefix=/usr/local/git install
  • 添加系统变量
    echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc

  • 使生效
    source /etc/bashrc
  • 验证
  • 删除源码
    rm -rf git-2.5.0 v2.5.0.tar.gz

svn安装

yum install subversion

  • 验证
    svnserve --version

jenkins构建配置


1
2
3
4
5
6
sonar.projectKey=mypay
sonar.projectName=mypay
sonar.projectVersion=1.0
sonar.sources=src/main
sonar.binaries=target/classes
sonar.exclusions=src/main/webapp/assets/**,src/main/webapp/plugins/**,src/main/webapp/mobile/**,src/main/ressources/**