python 自动克隆gitlab web前端
當本地master分支執行push動作的時候,服務器端會自動執行master分支的clone操作(還可以執行一些自動化腳本)
原理:
git hooks就是那些在git執行特定事件(如commit、push、receive等)后觸發運行的腳本。gitlab的web hooks跟git hook類似。也是當項目發生提交代碼、提交tag等動作會自動去調用url,這個url可以是更新代碼。或者其他操作。
?
寫一個最簡單的Python3 web服務:
from subprocess import call
from wsgiref.simple_server import make_server
import os
import time
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
#切換到服務器項目目錄
os.popen('cd /usr/local/service/tenant')
if os.path.isdir('ceshi'):
os.popen('rm -rf ceshi')
time.sleep(0.5)
os.system('git clone xxxxxx/ceshi.git')
print('git clone finish')
return "Thanks for your used!"
httpd = make_server('', 8009, application) # 監聽8009端口
print('Serving HTTP on port 8009...')
httpd.serve_forever()
運行這個簡單的web服務(將上面代碼保存為webhook.py,上傳服務器后執行python webhook.py 即可運行服務【注意:應該注意是否安裝Python,以及8009端口是否被占用】)
?
?
?
?
?
?
?
?
?
?
?
?注:借鑒@星塵博主的博客,表示感謝!!,外加根據自己項目需要做了修改和遇到的一些問題處理。(如有版權問題,請告知。立馬刪除)
轉載于:https://www.cnblogs.com/leeInvisible/p/11595887.html
總結
以上是生活随笔為你收集整理的python 自动克隆gitlab web前端的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery.extend 函数使用详解
- 下一篇: legend3---5、lavarel爬