您的位置:首页 > 其它

git实现自动化部署,同时push到多个远程仓库

2017-05-19 15:06 459 查看
方法一、
1、先在服务器创建裸仓库 git init --bare <repo> 裸仓库是可以被正常
clone
push
更新的, 裸仓库不包含工作区,所以并不会存在在裸仓库上直接提交变更的情况
git init --bare test.git
2、配置hooks 钩子
cd test/test.git/hooks/
vi post-receive
#!/bin/sh
git --work-tree=/root/test --git-dir=/root/test/test.git checkout -f #/root/test是代码目录,/root/test/test.git 是裸仓库

3、配置本地git conf
vi conf
[remote "web"]
url = git@git.oschina.net/mytest.git #远程仓库
url = 账号@ip:/root/test/test.git #服务器裸仓库
4、测试
git push web master

方法二、
1、配置码云
配置url和密码 (http://127.0.0.1/git_hooks,密码:123456)
2、配置服务器端

@login.route('/git_hooks', methods=['POST'])
def git_payload():
data = request.get_json()
password = '123456'
if data.get('password', None) == password:
if data.get('hook_name') == "push_hooks":
try:
cmd_output = subprocess.Popen(
[". /home/git_sh.sh"], shell=True)
return jsonify({'msg': str(cmd_output)})
except subprocess.CalledProcessError as error:
return jsonify({'msg': str(error.output)})
else:
return jsonify('invalid hooks')
else:
return jsonify('invalid hash')
3、编辑git_sh.sh脚本
cd /home/backend/www/aw
git pull origin master

4、over
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  上传 多个 git hooks