每次开发完提交代码到测试服务器都要进行相同的操作,是否可以直接触发操作?
gitlab服务器提供了此功能
这里分为几个部分,gitlab服务器(github,自己搭建的gitlab, oschian的码云),线上代码(测试代码,生产代码),开发代码
实现情景为:
开发代码完成,push到测试分支,触发push hook,hook 脚本(php http请求) 调用shell脚本,shell脚本执行拉取新代码操作,代码完成更新
贴关键节点代码:
hook链接:
http://192.168.10.175/hander.php
<?php // 处理 GitLab 请求的脚本 $rowData = file_get_contents('php://input', 'r');; $rowData = json_decode($rowData,true); $output = ''; echo 'begin----------'; // 只拉取 prod 分支的代码到服务器 #if($rowData['ref'] == 'refs/heads/prod'){ echo 'do----------'; // 触发拉取代码的脚本 exec('./pull',$output); var_dump($output); #} echo 'end----------'; shell脚本
#!/bin/bash # 拉取代码的脚本 cd /usr/local/nginx/html/molis git checkout pord git pull
这里需要其它功能大家可以自由发挥,比如上线配置需要更新配置文件,可以通过设置软链接来覆盖配置文件
转载请注明:朋克网 » git hook自动发布代码