溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

git實現自動化部署,同時push到多個遠程倉庫

發布時間:2020-06-18 17:58:59 來源:網絡 閱讀:1740 作者:boy12626 欄目:開發技術

方法一、

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、git實現自動化部署,同時push到多個遠程倉庫

??

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女