本地 windows 10 ,托管平台 码云 ,另一个远程仓库环境 Linux
1 首先码云新建仓库
2 windows 本地拉取刚才项目
3 linux拉取刚才新仓库
4 进入码云控制台刚才仓库-管理-WebHooks-添加
5,域名解析,nginx添加二级域名
vim xxx.conf, 修改server_name root wq!保存退出,
然后 service nginx restart 重启nginx
然后 cd /app
mkdir xxx
cd xxx
vim index.php <? phpinfo();
如果输出下图,说明webhooks配置成功
接下来修改index.php内容为
<?php $json = file_get_contents("php://input"); $data = json_decode($json,true); if (isset($data[‘ref‘]) && $data[‘total_commits_count‘]>0) { $res = PHP_EOL."pull start ---------------------------------------------".PHP_EOL; $res .= shell_exec("cd /app/xxx && git pull 2<&1 "); $res_log = ‘------------------------------------------------------------‘.PHP_EOL; $res_log .= $data[‘user_name‘] . ‘ 在‘ . date(‘Y-m-d H:i:s‘) . ‘向‘ . $data[‘repository‘][‘name‘] . ‘项目的‘ . $data[‘ref‘] . ‘分支push了‘ . $data[‘total_commits_count‘] . ‘个commit:‘.$data[‘commits‘][‘message‘]; $res_log .= $res.PHP_EOL; $res_log .= "pull end -----------------------------------------------------".PHP_EOL; file_put_contents("/home/wwwlogs/webhook/".date(‘Y-m-d‘,time()).".txt", $res_log, FILE_APPEND);//写入日志到log文件中 }
wq!保存退出
原文:https://www.cnblogs.com/aln0825/p/12054667.html