关于git post-receive 钩子

登录 git服务器

进入你项目所在git文件夹 

cd /var/opt/gitlab/git-data/repositories/liangyuquan/yfg.git

cd hooks

vim post-receive

 

#!/usr/bin/python
#-*- coding=UTF8 -*-
from fabric.api import env, run
from fabric.tasks import execute
from fabric.state import output
from fabric.decorators import runs_once
import datetime

now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

env.user = 用户名
env.password = 密码
env.hosts = ip
env.port = 端口

#注意以上参数要用 引号
@runs_once
def gitPull():
    global output
    output = run("cd /var/www/html/yfg && git pull").split()
# /var/www/html/yfg 要拉取的项目地址
execute(gitPull)
pulllog = "%s %s" % (now, output)
#print pulllog

f = open("/tmp/yfgGitHookPull.log", "a")
f.write(pulllog+'\n')        
f.close() 

 

posted @ 2017-06-07 15:58  GreenForestQuan  阅读(1760)  评论(0编辑  收藏  举报