git hook
<?php $requestBody = file_get_contents("php://input"); if (empty($requestBody)) { die('send fail'); } //解析码云发过来的JSON信息 $content = json_decode($requestBody, true); if($content['ref']=='refs/heads/dev'){ $logName = "git_".date('Ym'); //本地日志名称,与当前php文件在同一目录 file_put_contents($logName.".log", $requestBody. PHP_EOL, FILE_APPEND);//写入日志 //若是主分支且提交数大于0 $cmd = "cd /www/wwwroot && git reset --hard && git pull origin dev"; $result = shell_exec($cmd); //关键命令,拉取代码,2>&1后台执行 $res_log = "[ PULL START ]" . PHP_EOL; $res_log .= date('Y-m-d H:i:s') . '向' . $content['repository']['name'] . '项目的' . $content['ref'] . '分支push了' . $content['total_commits_count'] . '个commit:'. PHP_EOL; $res_log .= "[ PULL END ]" . PHP_EOL; $res_log .= PHP_EOL . PHP_EOL; file_put_contents($logName.".log", $res_log, FILE_APPEND);//写入日志 echo $res_log; $cmd = "cd .. && chmod -R 755 www.hahamiao.com && chown -R www:www www.hahamiao.com"; $result = shell_exec($cmd); //关键命令,拉取代码,2>&1后台执行 }else{ echo "not ref dev"; }