1
2
|
更新
发现一个很严重的问题,就是原始的gitlab-shell的hooks的东西绝对不能修改,还得必须是原来的东西。
|
post-receive还得是这个,如果改成git --work-tree=$web_dir checkout -f,去git拉取代码好像都不是最新的,慎重
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/env ruby
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
refs = ARGF.
read
key_id = ENV[
'GL_ID'
]
repo_path = Dir.
pwd
# reset GL_ID env since we already got its value
ENV[
'GL_ID'
] = nil
require_relative
'../lib/gitlab_custom_hook'
require_relative
'../lib/gitlab_post_receive'
if
GitlabPostReceive.new(repo_path, key_id, refs).
exec
&&
GitlabCustomHook.new.post_receive(refs, repo_path)
exit
0
else
exit
1
end
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
具体总结
su
- git
cd
/opt/git/repositories/xx/xx
.git
rm
-rf hooks
cp
-r
/opt/git/gitlab-shell/hooks
./
cd
hooks
rm
-rf pre-receive update
ln
-s
/opt/git/gitlab-shell/hooks/pre-receive
pre-receive
ln
-s
/opt/git/gitlab-shell/hooks/update
update
vim post-receive
#!/bin/bash
web_dir=
/opt/xx/xx/
git --work-tree=$web_dir checkout -f
git checkout不够好,更进一步看下面的链接
|
gitlab hook 加了expect
有时候,不需要定时同步。
参考上面的链接
#!/bin/sh
cur_dir=$(pwd)
web_dir=/opt/webroot/gitlab_hook/
#echo $cur_dir"/hooks" > /tmp/gitlab_hook_cur_dir.txt
#echo `whoami` > /tmp/gitlab_hook.txt
GIT_WORK_TREE=$web_dir git checkout -f
$cur_dir"/hooks/web_rsync" $web_dir > /tmp/gitlab_hook_rsync.log
web_rsync
#!/bin/bash
#ROOT="/data/www/wwwroot/bbs.linuxtone.org/"
SITE="xx"
USER="root"
PASSWORD="xx"
RSYNC_OPTS="-e \\\"ssh -p22 -o StrictHostKeyChecking=no\\\" -azuv --progress --exclude ".git" --bwlimit=150 --timeout=1200 -l"
auto_rsync() {
expect -c "eval spawn -noecho rsync $RSYNC_OPTS $1 $2
expect \"*?assword:*\"
send -- \"$PASSWORD\r\"
expect eof"
}
sync() {
FILE=$(basename $1)
DEST=$(dirname $1)
SRC=$1
# download remote site file to current location
#auto_rsync $USER@$SITE:$ROOT$FILE $DEST
auto_rsync $SRC $USER@$SITE:$DEST
# update remote site file if newer than backup
#auto_rsync $1 $USER@$SITE:$ROOT
}
# Remote file Directory
sync "/home/post-receive"
本文转自 liqius 51CTO博客,原文链接:http://blog.51cto.com/szgb17/1775314,如需转载请自行联系原作者