git实现自动化部署,同时push到多个远程仓库
方法一、
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、
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。