一、背景
gerrit提交的commit message 中的jira id 能自动关联到JIRA ,同gitlab与jira的集成
二、操作步骤
2.1 下载jar包,安装插件
下载链接:https://archive-ci.gerritforge.com/job/plugin-its-jira-bazel-master-stable-3.6/
安装命令
cp its-jira.jar /data/gerrit/gerrit_application/plugins
2.2 配置项目
该插件允许将 Jira 问题与 Git 提交关联起来。
可以针对每个项目配置是否启用 Jira 集成。要为项目启用 Jira 集成,项目必须在其project.config分支文件中包含以下条目refs/meta/config:
[plugin "its-jira"]
enabled = true
也可以在web页面上配置
2.3 添加gerrit.config配置
[its-jira]
url=https://jira.hobot.cc:8443
username=xxxxxx
password=xxxxxx
[commentlink "its-jira"]
match = ([A-Z]+-[0-9]+)
html = "<a href=\"https://jira.hobot.cc:8443/browse/$1\">$1</a>"
association = SUGGESTED
其他的不需要修改
MANDATORY : One or more issue-ids are required in the git commit message, otherwise the git push will be rejected.
SUGGESTED : Whenever a git commit message does not contain any issue-id, a warning message is displayed as a suggestion on the client.
OPTIONAL : Issue-ids are linked when found in a git commit message. No warning is displayed otherwise.
association三个参数根据需要调整
2.4 添加插件配置
配置文件:/data/gerrit/gerrit_application/etc/its/actions.config
[rule "open"]
event-type = patchset-created
action = add-standard-comment
action = invoke-issue-restapi POST /remotelink 200,201 link
#[rule "resolve"]
# event-type = comment-added
# approvalCodeReview = 2
# action = add-standard-comment
#[rule "merged"]
# event-type = change-merged
# action = add-standard-comment
#[rule "abandoned"]
# event-type = change-abandoned
# action = add-standard-comment
根据自身需要判断是否保留action = add-standard-comment
2.5 添加插件模板
模板文件:/data/gerrit/gerrit_application/etc/its/templates/link.soy
{namespace etc.its.templates}
{template .link}
{@param changeUrl: string}
{@param subject: string}
{@param status: string}
{lb}
"globalId": "{$changeUrl}",
"application": {lb}
"type": "com.googlesource.gerrit",
"name": "Gerrit"
{rb},
"object": {lb}
"url": "{$changeUrl}",
"title": "{$subject}",
"icon": {lb}
"url16x16": "https://gerrit.hobot.cc:8443/favicon.ico",
"title": "Review"
{rb},
"status": {lb}
{switch $status}
{case null}
"resolved": false
{case 'NEW'}
"resolved": false
{case 'SUBMITTED'}
"resolved": false
{case 'MERGED'}
"resolved": true
{case 'ABANDONED'}
"resolved": true
{/switch}
{rb}
{rb}
{rb}
{/template}
2.6 重启服务
/data/gerrit/gerrit_application/bin/gerrit.sh restart