gitblit服务器看不到源码,Redmine 和GitBlit仓库服务器整合

运行环境:

RedMine: 4.0.4

Git 仓库: Gitbilt V1.8.0

必须:

Redmine 安装并可运行

Redmine运行的主机里面已经安装了 Git,因需要在命令行中运行 git 命令

我运行的是bitnami的Redmine的Virtualbox 版本。地址是: Bitnami Redmine

启动虚拟机之后,开机完成之后,会出现

be401342c9d4760da28f7601407f1aed.png

访问地址

redmine 默认的登录的用户名和密码,redmine默认的登录密码也是 mysql root 用户的密码 Obtain MySQL Credentials

访问控制台(ssh)的默认用户名和密码

注: 如果 运行ifconfig 命令,提示ifconfig命令找不到,可以尝试运行sudo ifconfig

开始以为是没有安装 net-tools,尝试命令sudo apt install net-tools去安装,提示已经安装了。

debian

sudo rm -f /etc/ssh/sshd_not_to_be_run

sudo systemctl enable ssh

sudo systemctl start ssh

将仓库拷贝到本地

bitnami@debian:~$ cd ~

bitnami@debian:~$ mkdir gitrepos

bitnami@debian:~$ sudo chown -R www-data:www-data gitrepos

bitnami@debian:~$ sudo chmod -R a+rwx gitrepos

bitnami@debian:~$ cd gitrepos

bitnami@debian:~/gitrepos$ sudo -u www-data -H git clone --mirror git://192.168.1.142/test.git test

是将对应项目的git镜像到本地(不是源码下载到本地哦)

Readmine 配置

查看 Git 是否可用

cde6cfc63e37d7ee5b48e4ae9e85a252.png

给项目新建版本库

bc15f2b58ef1166f375ee8f5be5c7396.png

a11d27fd43354f7b1341bdc560ec5f91.png

修正: 库路径结尾没有.git ,因为上面已经取了别名是test

查看是否能正常显示源码

c9c5cde505374bc325aa6ea760058ffe.png

ffce878cf41704bf7e999cf39f71e40c.png

从上图可以看到,成功显示源码和提交历史。如果开始是一个空仓库,可能会提示类似"该目录下没有条目或者文件"

使用 Linux的定时任务定时拉取仓库

创建一个 shell 文件,如: git_repo_test.sh,内容

#!/bin/bash

cd /home/bitnami/gitrepos/test && sudo -u www-data -H git fetch

保存之后,尝试运行脚本,运行成功,

930017e35ba0a51fbdb4bdf8c8cb01f9.png

下一步将定时每5分钟运行这个脚本

crontab -e

在打开的crontab 编辑文件中添加

*/5 * * * * cd /home/bitnami/gitrepos/test && sudo -u www-data -H git fetch

编辑完之后,重启 cron 服务

sudo service cron restart

最后在 Redmine中,看到 仓库的更新记录,如果有新提到远程仓库,5分钟之后,会通过定时任务自动拉取提交的记录

其它 Redmine和GitBilt 集成

在管理,版本库,开启 Web Service,并生成key 和 对Readmine的通知

04a5956e1e61804f1c9132164dc1c515.png

e7e623746cd08cc52e60486cfc9693ae.png

跟踪标签

用于解决问题的关键字

应用后的状态

% 完成

全部

fixes,fixed

Resolved

80%

全部

closes,closed

Closed

100%

全部

developing,doing

In Progress

20%

开启 Readmine的API

be5c9d152d445e3a97cced87ab43e237.png API选项卡 里面的两个都勾选

修改Gitbilt 配置文件

修改 Gitbilt 文件夹下data 的 gitblit.properties 文件

在文件夹中,添加

groovy.customFields = "redmineProject=Redmine Project Identifier"

最后我的gitblit.properties的内容是:

#

# GITBLIT.PROPERTIES

#

# Define your custom settings in this file and/or include settings defined in

# other properties files.

#

# Include Gitblit's 'defaults.properties' within your configuration.

#

# NOTE: Gitblit will not automatically reload "included" properties. Gitblit

# only watches the 'gitblit.properties' file for modifications.

#

# Paths may be relative to the ${baseFolder} or they may be absolute.

#

# COMMA-DELIMITED

# SINCE 1.7.0

include = defaults.properties

groovy.customFields = "redmineProject=Redmine Project Identifier"

#

# Define your overrides or custom settings below

#

#git.repositoriesFolder=E:\devops\gitblit\repos

server.httpPort=10101

server.httpBindInterface=0.0.0.0

#tickets.service = com.gitblit.tickets.FileTicketService

#tickets.acceptNewTickets = true

修改 GitBilt 的redmine-fetch.groovy 文件

修改 GitBilt 安装文件夹下,修改data/groovy 文件夹下的 redmine-fetch.groovy 文件,修改 redmineURL和apiKey 2个变量的值,修改的值如下:

/*

* This script triggers automatic repo fetches in Redmine upon pushes.

* It won't work out-of-box, you need to configure a few things.

*

* Redmine

* - Go to Administration / Settings / Repositories, and make sure that the

* "Enable WS for repository management" option is checked. Also generate an

* API key and take note of it.

* - Open a project page, go to Settings / Repositories and add a repo. Take

* note of the Identifier.

*

* Gitblit

* - Set the redmineProject custom field in gitblit.properties, e.g.

* groovy.customFields = "redmineProject=Redmine Project Identifier"

* - Edit the repo you added to Redmine, go to hook scripts and add this script

* to the post-receive hooks. Also specify the Redmine project's identifier

* under custom fields.

*

* Troubleshooting

* - run Gitblit interactively and check its console output

* - on the Redmine server, tail -f log/access.log

*

* If you want your repos to work with multiple Redmine projects, you don't need

* to add the repos to all of them. Instead, add the repo to a single project,

* then go to Administration / Settings / Repositories and enable the "Allow

* issues of all the other projects to be referenced and fixed" option.

*/

/* specify the URL of your Redmine instance here */

def redmineURL = "http://192.168.1.114/"

/* specify the API key you generated in Redmine Administration here */

def apiKey = "R15mHY73KaTzUpCDmOYr"

/*

* construct the URL from global and repo properties, for more info refer to

* http://www.redmine.org/projects/redmine/wiki/RedmineSettings#Fetch-commits-automatically

*/

def triggerURL = redmineURL + "sys/fetch_changesets?id=" + repository.customFields.redmineProject + "&key=" + apiKey

/* log the action */

logger.info("Redmine Fetch hook triggered by ${user.username} for ${repository.name}: GET ${triggerURL}")

/* send the HTTP GET query */

new URL(triggerURL).getContent()

修改完之后,重启启动GitBilt

下一步,在 版本库列表,进入仓库 test详情页,点击右上角的 "编辑"按钮

d038859a01e289df5d111562e02d20de.png

进入编辑页面之后,选择receive 选项卡,进入Receive 设置页面

48f9b548eed7ba76aefa2d1ba3ad7225.png

最后 给 test仓库推送提交,GitBilt的命令窗口显示,请求Redmine的Api地址成功

8d7d9552dfa1166af2843ac1cc864ccd.png

bitnami redmine 程序的命令备忘

sh /opt/redmine-3.4.4-1/ctlscript.sh restart

sh /opt/redmine-3.4.4-1/ctlscript.sh restart mysql

/opt/redmine-3.4.4-1/ruby/bin/bundle install --path vendor/bundle

sudo /opt/redmine-3.4.4-1/mysql/bin/mysqld_safe --pid-file=/opt/redmine-3.4.4-1/mysql/data/mysqld.pid --datadir=/opt/redmine-3.4.4-1/mysql/data --init-file=/home/test/mysql-init 2> /dev/null &

/opt/redmine-3.4.4-1/mysql/bin/mysqldump -A -u root -p > backup.sql

References

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值