关于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() 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM