Gerrrit Jenkins Gitlab 打造codereview平台
1. 环境配置(ubuntu)
-
Git 安装
sudo apt-get install git
-
JDK安装
sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-8-jdk //当前安装为 jdk1.8.0_101
配置java环境变量
vi /etc/profile export JAVA_HOME= /usr/java/jdk1.8.0_101/ export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH source /etc/profile java -version
-
gerrit 安装
-
项目下载地址
http://gerrit-releases.storage.googleapis.com/index.html -
安装Gerrit
sudo java -jar gerrit-2.11.3.war init -d /opt/gerrit/ 直接根据情况来执行就可以了,记住,要在SMTP配置的地方配置好,不然,之后发邮件发不了,重新配置就比较麻烦
-
安装apache2相关组件
sudo apt-get update sudo apt-get upgrade sudo apt-get clean sudo apt-get install apache2 #安装apache2 sudo apt-get install apache2-utils sudo a2enmod proxy_http #开启代理模块 sudo a2enmod proxy_balancer #开启负载均衡模块 sudo apt-get install libapache2-mod-php php sudo apt-get install php-curl sudo service apache2 restart #启动apache2
-
apache2 配置
sudo vi /etc/apache/ports.conf NameVirtualHost *:8084 Listen 8084 NameVirtualHost *:8090 Listen 8090 <IfModule ssl_module> Listen 443 </IfModule> <IfModule mod_gnutls.c> Listen 443 </IfModule>
sudo vi /etc/apache2/sites-available/gerrit.conf
<VirtualHost *:8090> ServerName 127.0.0.1 ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> <Location /login/> AuthType Basic AuthName "Gerrit Code Review" Require valid-user AuthBasicProvider file AuthUserFile /opt/gerrit/pwd </Location> AllowEncodedSlashes On ProxyPass / http://127.0.0.1:8088/ </VirtualHost>
sudo a2ensite gerrit.conf #启用该代理 sudo service apache2 restart
-
Gerrit 配置
配置:[gerrit] basePath = git serverId = 3b697ff4-1ecf-4bfb-91aa-7c7c87d4f4e0 canonicalWebUrl = http://devops.smzdm.com:8090/ [database] type = h2 database = /opt/gerrit/db/ReviewDB [index] type = LUCENE [auth] type = HTTP [receive] enableSignedPush = false [sendemail] enable = true smtpServer = smtp.aliyun.com smtpServerPort = 465 smtpUser = eric_ji@aliyun.com smtpEncryption = ssl sslVerify = false smtpPass = ji88173803 from = SMZDM-CodeReview<eric_ji@aliyun.com> [container] user = root javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre [sshd] listenAddress = *:29418 [httpd] listenUrl = proxy-http://*:8088/ [cache] directory = cache
配置一下Gerrit启动脚本:
sudo cp /opt/gerrit/bin/gerrit.sh /etc/init.d/gerrit sudo vim /etc/init.d/gerrit GERRIT_SITE=/opt/gerrit/ # 在代码 47 行增加 sudo update-rc.d gerrit defaults 21 sudo service gerrit restart #确保Gerrit已经关闭, 不然会出错
添加gerrit账号信息
sudo touch /opt/gerrit/pwd sudo htpasswd /opt/gerrit/pwd XXX
安装完成后, 在浏览器输入:ip:8090, 应该会弹出一个登录框, 输入上面设置的XXX用户名密码即可
-
-
2. jenkins配置
- Jenkins 先安装Gerrit Trigger插件
- Jenkins新建gitlab仓库中同名项目(自由风格)
- 定义参数化构建过程 [图片上传失败...(image-be3172-1545991897673)]
- 代码来源配置 [图片上传失败...(image-6e2131-1545991897673)]
- Build Triggers 配置 [图片上传失败...(image-927f96-1545991897673)]
- Buid 配置 [图片上传失败...(image-3337ff-1545991897673)]
3. replication 配置,同步代码到gitlab
- 安装gerrit replication 插件
- 配置ssh config,在gitlab中添加sshkey
Host gitlab-team.smzdm.com User jixiangxiang@smzdm.com Port 22222 IdentityFile ~/.ssh/id_rsa StrictHostKeyChecking no UserKnownHostsFile /dev/null PreferredAuthentications publickey
- 配置replication.config
[remote "gitlab-team.smzdm.com"] url = gitlab@gitlab-team.smzdm.com:android/${name}.git push = +refs/heads/*:refs/heads/* push = +refs/tags/*:refs/tags/* push = +refs/changes/*:refs/changes/* timtout = 30 threads = 3
网友评论