GitLab集成Jira
环境说明:
- GitLab地址
- Jira地址
1. Jira安装
官方文档:
1.1 下载Jira
选择Get started
, Linux 64 bit
atlassian-jira-software-8.17.0-x64.bin
1.2 安装Jira
chmod a+x atlassian-jira-software-*-x64.bin
sudo ./atlassian-jira-software-*-x64.bin
- 选择
Express Install
(option 1) - 安装完成后,Jira web服务监听在8080端口
1.3 设置Jira
浏览器打开jira,根据向导设置Jira
- 选择
single node
- 创建账号
-
generate a license
,这一步需要连外网、申请Jira试用密钥
1.4 Jira启用https
- 安装apache
yum install httpd mod_ssl
- 准备https证书
可以购买收费的https证书,这里用lets encrypt申请免费的证书:
- 安装certbot
- 申请https证书
certbot certonly --standalone -d $domain
- 将
/etc/letsencrypt/live/$domain
下的cert.pem
,privkey.pem
,chain.pem
拷贝到/etc/httpd/ssl/
目录下
- 设置apache反向代理
修改/etc/httpd/conf.d/ssl.conf
Listen 443 https
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
SSLSessionCache shmcb:/run/httpd/sslcache(512000)
SSLSessionCacheTimeout 300
SSLRandomSeed startup file:/dev/urandom 256
SSLRandomSeed connect builtin
SSLCryptoDevice builtin
<VirtualHost *:443>
ServerName jira.devxops.com
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCertificateFile /etc/httpd/ssl/cert.pem
SSLCertificateKeyFile /etc/httpd/ssl/privkey.pem
SSLCertificateChainFile /etc/httpd/ssl/chain.pem
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
# Jira Proxy Configuration:
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
重启apache:
systemctl restart httpd
- Jira使用反向代理
- 备份
/opt/atlassian/jira/conf/server.xml
,然后修改该文件 - 将文件中的这段配置复制一段放到上方,然后把这段配置的端口从8080改到8081
- 在上面那段配置下增加https代理配置,注意
proxyName
改成自己的域名
两端配置如下:
<Connector port="8080" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^\`"<>"
maxThreads="150" minSpareThreads="25" connectionTimeout="20000" enableLookups="false"
maxHttpHeaderSize="8192" protocol="HTTP/1.1" useBodyEncodingForURI="true"
acceptCount="100" disableUploadTimeout="true" bindOnInit="false"
scheme="https" proxyName="jira.devxops.com" proxyPort="443"/>
<!-- Relaxing chars because of JRASERVER-67974 -->
<Connector port="8081" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^\`"<>"
maxThreads="150" minSpareThreads="25" connectionTimeout="20000" enableLookups="false"
maxHttpHeaderSize="8192" protocol="HTTP/1.1" useBodyEncodingForURI="true"
acceptCount="100" disableUploadTimeout="true" bindOnInit="false"/>
- 重启jira
/opt/atlassian/jira/bin/stop-jira.sh
/opt/atlassian/jira/bin/start-jira.sh
2. GitLab集成Jira
官方文档和视频:
2.1 GitLab创建用户、group
和project
- 创建用户,email等信息与Jira中的用户对应
- 创建一个
test-group
- 在上面的组中创建一个
test-project
2.2 Jira启用OAuth2
- 管理 > 系统 > 一般配置 > 基本url, 修改为https开头的域名
- 管理 > 系统 > OAuth 2.0.
- 新增一个集成
-
服务提供商
选择自定义
- 填入集成名称
-
客户ID
和客户机密
暂时留空,将在下一步设置 - 填写
授权端点
和令牌端点
,分别是:
https://gitlab.devxops.com/oauth/authorize
https://gitlab.devxops.com/oauth/token
- 点击
Generate
生成重定向URL
,复制以便于下一步操作
2.3 GitLab创建Jira Applications
- 用户设置 > Applications,增加新的Application
- Redirect URI: 填入从Jira拷贝的
重定向URL
- Confidential: 选中
- Scopes: 输入并新建
api
- 提交
- Redirect URI: 填入从Jira拷贝的
- 提交后就能得到Application ID和Secret
2.4 完成Jira OAuth2设置
- 填入GitLab Application ID、Secret
- 范围选择
api
- 保存并测试连接
2.5 Jira链接GitLab账号
- Jira管理 > 应用程序 > DVCS Accounts.
- 点击
链接账户
-
Host
选择GitLab Self-Managed
-
Host URL
填写https://gitlab.devxops.com
-
Team or User Account
填写GitLab的组名,例如:test-group
- 点击
增加
- 按照向导执行剩下的操作,之后就可以把GitLab的
test-group
和test-project
与Jira关联起来
3. GitLab集成Jira的用法
3.1 Jira Issue跟踪、智能提交、开发面板集成
在GitLab 提交信息、合并请求信息中提及Jira Issue ID,可以:
- 在Jira Issue面板中展示关联的GitLab提交、合并请求信息
- 在GitLab提交、合并请求信息中直接打开关联的Jira Issue
- 评论Jira Issue
- 设置Jira Issue状态
- 设置Jira Issue处理时间
MSP-2 #comment some msg #in-progress #time 2d
MSP-2 #done
3.2 GitLab导入Jira Issue
- GitLab Project Settings → Integrations → Jira
- 填入Jira URL、Username、Password
- 选中Active
- 保存
- 新建一个空的GitLab Project,进入Issues → Import Issue → From Jira
- 选择Jira Project
- continue
该文档来源自Alex 和 Hu Peng,感谢两位!