https://gerrit-ci.gerritforge.com/view/Plugins-master/job/plugin-its-jira-bazel-master/ 只能找到新版本的jar包,因为使用 Gerrit 版本较老(2.16.4),只能下载源码,自己编译。
准备
To build Gerrit from source, you need:
- A Linux or macOS system (Windows is not supported at this time)
- A JDK for Java 8|9|10
- Python 2 or 3
- Node.js
- Bazel
- Maven
- zip, unzip
- gcc
一、安装 bazel
1、在 Ubuntu 上安装 Bazel
华为云镜像资源:https://mirrors.huaweicloud.com/bazel/
具体安装参考:https://zhuanlan.zhihu.com/p/661422615
# 选择版本
wget https://mirrors.huaweicloud.com/bazel/3.1.0/bazel-3.1.0-installer-linux-x86_64.sh
chmod +x bazel-3.1.0-installer-linux-x86_64.sh
./bazel-3.1.0-installer-linux-x86_64.sh --user
# 添加环境变量
vi /etc/profile
# 在出现的文件中末尾添加以下配置
export PATH="$PATH:$HOME/bin"
source /etc/profile
# 验证
bazel --version
二、编译
1、下载源码
gerrit
its-jira
its-base
https://gerrit.googlesource.com/
对应的国内地址:https://gerrit-googlesource.proxy.ustclug.org/
git clone --recurse-submodules https://gerrit-googlesource.proxy.ustclug.org/gerrit -b stable-2.16
cd gerrit
cd plugins
git clone https://gerrit-googlesource.proxy.ustclug.org/plugins/its-jira -b stable-2.16
git clone https://gerrit-googlesource.proxy.ustclug.org/plugins/its-base -b stable-2.16
2、执行编译
2.1 build standalone:目前只有少数插件支持该模式
2.2 build in gerrit tree
本文使用build in gerrit tree
方式编译
# Some plugins describe their build process in src/main/resources/Documentation/build.md file. It may worth checking.
# 在gerrit目录下执行
cd ../
bazel build plugins/its-jira
参考:
https://zhuanlan.zhihu.com/p/41754681
https://blog.csdn.net/qq_15371293/article/details/128844347
https://gerrit-review.googlesource.com/Documentation/dev-bazel.html
https://gerrit-review.googlesource.com/Documentation/cmd-plugin-install.html
https://gerrit-review.googlesource.com/Documentation/dev-build-plugins.html
三、安装插件并进行配置
1、将插件的jar包放到$site_path/plugins/
目录(一般为/var/gerrit/plugins
或/var/gerrit/review_site/plugins
目录,无需重启gerrit)。
2、在gerrit.config
文件中添加its-jira
配置
# 配置所有项目启动 jira 集成
[plugin "its-jira"]
enabled = true
# 制定git提交策略
# MANDATORY:commit message 需要包含一个或多个 issue-id,否则 git 推送将被拒绝
# SUGGESTED:commit message 不包含任何 issue-id 时,会在客户端上显示一条警告消息作为建议。
# OPTIONAL:在 commit message 中检测到 issue-id 时,就会和 jira 上的 issue 关联;没检测到也不会报错。
[commentLink "its-jira"]
match = ([A-Z]+-[0-9]+)
html = "<a href=\"http://10.4.0.233:8090/browse/$1\">$1</a>"
association = SUGGESTED
# 配置 jira 凭据
[its-jira]
url=http://10.4.0.233:8090
username = admin
password = admin
3、在/var/gerrit/review_site/etc
目录创建its
目录存放配置文件actions.config
mkdir -p $GERRIT_SITE/etc/its/
vi $GERRIT_SITE/etc/its/actions.config
[rule "rule1"]
event-type = comment-added
approvalCodeReview = -2,-1
action = add-comment Oh my Goodness! Someone gave a negative code review in Gerrit on an associated change.
4、重启容器使配置生效
docker restart gerrit
参考:
https://ahsan.io/2018-10-12-gerrit-jira/
https://community.atlassian.com/t5/Jira-Software-questions/How-can-I-integrate-Gerrit-with-Jira-Cloud/qaq-p/918477
https://stackoverflow.com/questions/21328402/how-to-connect-jira-and-gerrit
四、JIRA配置
1、安装Git Integration for Jira插件
2、如果想在 issue 页面上预览 Gerrit Reviews,需要安装 Gerrit Code Review for Jira 插件。
3、配置jira集成Gerrit
image.png参考:https://help.gitkraken.com/git-integration-for-jira-data-center/git-integration-for-jira-home-self-manged/
https://github.com/MeetMe/jira-gerrit-plugin/blob/master/README.md
五、测试
1、gerrit创建test项目
2、jira创建test项目,并创建ISSUE
3、gerrit创建新的提交,在commit message
中填写issue id
。
此时,可以通过点击上图箭头指向的TEST-1
跳转到jira的issue页面。同时在jira issue页面可以看到处理该问题的提交。
网友评论