Redmine与Gitlab功能集成

启用版本库

 

管理账号登陆:

  1. 启用SCM:本地只安装了git,所以其他的取消掉
  2. 启用用于版本库管理的Web Service:需要勾选,实现gitlab的web_hook访问
  3. 版本库管理网页服务API密钥:点击生成或者手动输入,记录一下后面配置gitlab需要用到
  4. 允许引用/修复所有其他项目的问题:勾选后就可以在commit message中使用上一项定义的关键字实现git提交和redmine issue的关联,如 refs:#123 表示将本次提交关联到redmine的123号任务
  5. 激活时间日志:勾选后可以在commit message中设置当前提交耗时记录,方式为 Implement feature #1234 @2h 或者 Implement feature #1234 @15m
  6. 最下面一个设置框中就是自定义关键字,实现commit message控制remine中的issue的状态,比如我这里预设了解决、进行中和关闭三个,在commit message中的用法为: ok:#123 或 start #123 或 close:#123 @2 ,这最后一个实例还把时间也带上了。

 

克隆代码版本库

 

1. 创建代码库目录,设置用户和用户组

[root@localhost ~]# mkdir /git-repo
[root@localhost ~]# chown daemon:daemon /git-repo

2.给daemon用户生成ssh key

[root@localhost ~]# mkdir /usr/sbin/.ssh
[root@localhost ~]# chown daemon:daemon /usr/sbin/.ssh
[root@localhost ~]# sudo -u daemon -H ssh-keygen -t rsa
[root@localhost ~]# cd /usr/sbin/.ssh
[root@localhost .ssh]# ll
总用量 8
-rw-------. 1 daemon daemon 1675 10月 18 13:37 id_rsa
-rw-r--r--. 1 daemon daemon  410 10月 18 13:37 id_rsa.pub

3.将上一步生成的文件/usr/sbin/.ssh/id_rsa.pub的内容添加到自己gitlab的SSH Keys中,以便无密码获取代码库

4.克隆代码版本库

[root@localhost ~]# cd /git-repo
[root@localhost git-repo]# sudo -u daemon -H git clone --mirror git@192.168.230.184:root/Test.git Test
克隆到裸版本库 'Test'...
The authenticity of host '192.168.230.184 (192.168.230.184)' can't be established.
ECDSA key fingerprint is a7:ab:c0:dd:71:14:90:dc:36:4f:34:f5:6a:78:f2:f8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.230.184' (ECDSA) to the list of known hosts.
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 9 (delta 0), reused 0 (delta 0)
接收对象中: 100% (9/9), done.

四、项目启用版本库

1、创建测试项目

(1)、SCM:选择git,在 2.1的设置 中只勾选了git

(2)、主版本库:如果勾选了这个在项目的导航条上就会新增一个tab—版本库,不勾选,就需要通过 配置—版本库 查看

(3)、标识:是版本库的一个名字

(4)、库路径:就是前面执行git clone生成的目录的路径,注意:redmine需要有该目录的读写权限,否则点击版本库会出现404错误

(5)、路径编码:优选UTF-8

(6)、报告最后一次文件/目录提交:建议勾选,选上后打开版本库会看到相关文件最后一次提交的相关信息如作者、commit message等

 

启用自动更新版本库

 

1、使用 cron 设置定时任务方法

[root@localhost Test]# crontab -l
*/1 * * * * cd /git-repo/Test && sudo -u daemon -H git remote update

2、使用 redmine_gitlab_hook 插件方法(推荐)

(1)、安装插件

[root@localhost ~]# cd /opt/redmine-3.4.6-3/apps/redmine/htdocs/plugins
[root@localhost plugins]# sudo -u daemon -H git clone https://github.com/phlegx/redmine_gitlab_hook.git
[root@localhost plugins]# /opt/redmine-3.4.6-3/use_redmine #进入到特定的bash环境下
bash-4.2# cd ..
bash-4.2# pwd
/opt/redmine-3.4.6-3/apps/redmine/htdocs
bash-4.2# gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
bash-4.2# yum install gcc libxslt-devel libxml2-devel -y
bash-4.2# bundle install --without development test --no-deployment #可能会安装依赖,较耗时
bash-4.2# bundle exec rake redmine:plugins RAILS_ENV=production
bash-4.2# /opt/redmine-3.4.6-3/ctlscript.sh restart
bash-4.2# exit #退出bash

(2)、插件配置

(2)、GitLab配置

 

 

URL 的格式为:

{redmine_installation_url}/gitlab_hook?key={redmine_repository_API_key}&project_id={redmine_project_identifier}&repository_name={redmine_repository_identifier}

 

URL:

http://192.168.230.163/redmine/gitlab_hook?&key=vv1hlV9JyI2u9PUElVEY&project_id=testproject&repository_name=test

说明: testproject 为项目标识,test 为版本库标识

 

如果报错:

https://docs.gitlab.com/ee/security/webhooks.html

大致意思 gitlab 10.6 版本以后为了安全,不允许向本地网络发送webhook请求,如果想向本地网络发送webhook请求,可进入Admin area,在Admin area中,在settings标签下面,找到OutBound Request,勾选上Allow requests to the local network from hooks and services ,保存更改即可解决问题。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值