Gerrit Code Review Advanced Practice Gerrit Code Review Advanced Practice

Gerrit Code Review Advanced Practice

Gerrit Code Review Advanced Practice

Gerrit is a free, open source code review software that uses a web interface. Using a web browser, programmers on the same team can review each other's modified program code and decide whether to submit, return or continue to modify. it uses  git as the underlying version control system.

In "Introduction to Gerrit Code Review" , Dong Lin, the senior technical director of GeTui, mentioned that the code review before storage is more cost-effective and the timing is better. He also focused on the Gerrit installation and deployment, the normal code submission process, the complete submission process and the single submission process. This issue of "Gerrit Code Review Advanced Practice" will introduce Jenkins integration, Email notification, Gerrit and Related content of external Git repository synchronization and temporary packaging and testing before storage.

1. High-level combat - Jenkins integration

Before implementing Jenkins integration, Gerrit-related preparations must be completed.

Configure the verify account. The verify account here is provided to jenkins. You need to provide the ssh public key of the computer where jenkins is located, and fill in the area shown in the figure below. You can also use http to configure the verify account.

Add events-log plugin. The events-log plugin does not belong to the default integration, and the official jar package download is not provided, so you need to compile it yourself.

编译命令  “buck build plugins/<plugin-name>:<plugin-name>”
输出目录  “buck-out/gen/plugins/<plugin-name>/<plugin-name>.jar”

As shown below

The installation process is relatively simple. Copy the event-log.jar package to the "gerrit/review_site/plugins" directory and restart it.

Introduction to Jenkins

Jenkins is a widely used automation solution and a continuous integration based on Java development工具,用于监控持续重复的工作,功能包括持续的软件版本发布/测试项目以及监控外部调用执行的工作。目前最新的Jenkins2.0主推CI和CD的概念,能通过Jenkins系统便捷的完成工作流,包括从编译,测试到发布等。

Jenkins安装配置

Jenkins 提供多种安装方式,根据实际情况自行选择,本文的安装环境是ubuntu,因此采用了apt-get 方式。

启动命令 “service Jenkins start”,安装Gerrit Trigger插件,进入Jenkins 提供的插件安装界面,选择GerritTrigger 插件,进行安装。(可能需要发挥小伙伴们的聪明才智绕过访问限制)

安装gerrit-trigger后 “系统管理” 页面中会出现 “GerritTrigger ”选项,进入填写相关配置。

需要注意的是,Username字段需要和 Gerrit 系统中verify功能配置的账号对应。

填写好后,点击Test Connection测试,如果出现异常,逐个检查配置是否正确。

接着,添加Job,配置Gerrit触发条件和执行动作。

Gerrit Trigger提供多种触发条件,这里主要是提供verify功能,选择Patchset Created选项,在任何修改提交到Gerrit上时,进行CI(Continuous integration ,持续集成)自动构建,在Dynamic Trigger Configuration选项里面填写工程名,监听分支名,这样当master 分支有变动的时候就会自动触发该job。

验证测试

提交change

测试上一步操作中添加的gexin-test工程。

检查Verified状态

提交后打开Gerrit,发现该次提交的verify已经通过(注意:这里并没有进行真实的verify工作,需要根据项目实际情况定义verify具体内容)。

检查Jenkins Job日志

打开 jenkins里面的job console,可以看到该次verify的具体日志,用于排查问题等。

二、高阶实战-Email通知

Gerrit配置smtp参数,Gerrit自带了邮件提醒功能,可watch 不同项目,不同事件,根据实际需要配置 “~/gerrit/review_site/etc/gerrit.config”文件,如图所示。

配置Email通知事件

gerrit设置界面提供了通知时间选择。

自定义邮件模板

“~/gerrit/review_site/etc/mail”目录下提供各种事件邮件模板,可根据需求修改。 参考(Gerrit Code Review)。

三、高阶实战-Git仓库同步

Replication插件提供了自动同步工程功能,Gerrit安装时可默认选择安装

$site_path/etc/replication.config。

配置可参考下图

配置好后,上文中commit点入库后,自动同步到github,实现Replication复制功能。

四、高阶实战-入库前临时打包测试

Gerrit直接下载相应的tgz包

在实际工作中,会遇到commit点在reivew的时候需要打包看效果的情况,这时reviewer可以打包下载代码,或者git fetch改点代码,地址如下图所示。

五、Gerrit闲谈

1、关于Android Code Review工作流

上图Google针对Android系统源码开发所采用的代码审核入库流程,比较严格,因为系统源码的问题是影响非常深远的。在实际项目执行中,可以参照该流程进行相应简化,在敏捷和规范间做个权衡。

2、Gerrit数据备份

代码安全永远是重中之重,定期对整个$site_path目录进行备份是必不可少的。可以通过脚本自动备份和压缩Gerrit库,并且保存到另外一个地方。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325541627&siteId=291194637