gitlab 使用原始的hooks同步到某一个目录

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不够好,更进一步看下面的链接

利用git push向服务器一键部署代码 //

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,如需转载请自行联系原作者

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值