python automatic clones gitlab web front end


    When push the local master branch to perform the action, the server automatically executes the master branch of the clone operation (can also perform some automated scripts)

principle:

    git hooks script is run after those executed git particular event (such as commit, push, receive, etc.) trigger. gitlab the web hooks similar with git hook. When the project also occurred submit code, and other actions will automatically submit tag to call the url, the url can be updated code. Or other operations.

 

Write a simple Python3 web services:

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


Run this simple web service (save the above code webhook.py, execute python webhook.py to run the service after the upload server [Note: It should be noted that whether to install Python, and 8009 port is occupied])

 

 

 

 

 

 

 

 

 

 

 

 Note: learn @ Stardust bloggers blog, thank! ! Plus projects according to their need to do some modification and processing problems encountered. (Subject to copyright issues, please let me know. Immediately deleted)

Guess you like

Origin www.cnblogs.com/leeInvisible/p/11595887.html