配置gitlab服务器的git hooks 钩子

root是某个gitlab用户

xxx.git是xxx项目的git仓库根目录

在gitlab里
目录 /var/opt/gitlab/git-data/repositories/root/xxx.git/hooks/
是一个连接指向/opt/gitlab/embedded/service/gitlab-shell/hooks/

我们需要到
目录/var/opt/gitlab/git-data/repositories/root/xxx.git/下
新建 custom_hooks目录

把post-receive放在该目录下。

操作如下

#切换目录
cd /var/opt/gitlab/git-data/repositories/root/xxx.git

#创建钩子目录
mkdir custom_hooks

#赋给权限
chown git:git custom_hooks
chmod 755 custom_hooks

cd custom_hooks
#创建 post-receive 钩子
vi post-receive 
#保存post-receive内容后

#赋给权限
chown git:git post-receive
chmod 755 post-receive

#切换项目根目录
cd /var/www/html
mkdir erp
chmod 777 -R erp


post-receive的内容

#!/bin/bash

#  /var/www/html/erp是你项目的根目录 checkout -f 是自动检出
git --work-tree=/var/www/html/erp checkout -f
# master是需要检出的分支
BRANCH=master

while read oldrev newrev ref
do
    if [[ $ref =~ .*/${BRANCH}$ ]];
    then
        echo "$BRANCH ref received.  Deploying $BRANCH branch to testserver..."
        git --work-tree=${GIT_WORK_TREE} checkout ${BRANCH} -f
    else
        echo "Ref $ref successfully received.  Doing nothing: only the $BRANCH branch may be deployed on this server."
    fi
done

 

详见:https://docs.gitlab.com/ee/administration/custom_hooks.html
参考:https://blog.csdn.net/daisho/article/details/83272801 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值