gitlab自动同步代码到web站点
备注:还未亲自测试,但感觉可行!
1、进入网站目录,克隆仓库代码
|
1
2
3
4
|
cd /www/wwwroot/git clone http://192.168.3.141:8099/liujuncheng/test.git testchmod -R 777 testchown -R www:www test |
2、设置git自动更新的钩子文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
cd /var/opt/gitlab/git-data/repositories/liujuncheng/test.git/hooksvi post-receive#文件内容,将原有的文件备份,并清空写入以下文件内容#!/bin/bash#获取当前目录DIR_NAME=$( cd $(dirname $BASH_SOURCE) && pwd)#创建数组,根据/进行分割array=(${DIR_NAME//// })#获取最后第二个元素s_value=${array[${#array[*]}-2]}#创建数组,根据.进行分割array2=(${s_value//./ })#获取第一个元素s2_value=${array2[0]}#echo $s2_value#git --work-tree=/www/wwwroot/$s2_value checkout -fgit --work-tree=/www/wwwroot/$s2_value clean -fdgit --work-tree=/www/wwwroot/$s2_value checkout --forcesudo chown -R www.www /www/wwwroot/$s2_valuesudo chmod -R 777 /www/wwwroot/$s2_value |
3、设置钩子文件的执行权限
|
1
|
chmod +x post-receive |
4、将git用户放入www用户组
|
1
|
usermod -a -G www git |
5、让git无密码sudo
|
1
2
3
|
vi /etc/sudoers#追加写入git ALL=(ALL) NOPASSWD: ALL |
版权声明:
作者:admin
链接:http://blog.mryxh.cn/1678.html
文章版权归作者所有,未经允许请勿转载。
THE END