码云webhook文件
1 <?php 2 //git webhook 自动部署脚本 3 //项目存放物理路径 4 $path = "/www/wwwroot/test/crmeb_doctor/"; 5 $requestBody = file_get_contents("php://input"); 6 if (empty($requestBody)) { 7 die('send fail'); 8 } 9 $content = json_decode($requestBody, true); 10 $password='kuai1234'; 11 // writelog(json_encode($json)); 12 if (empty($content['password']) || $content['password'] !== $password) { 13 exit('error request'); 14 } 15 16 //若是主分支且提交数大于0 17 if ($content['ref']=='refs/heads/master' && $content['total_commits_count']>0) { 18 $res = shell_exec("cd {$path} && git pull 2>&1");//以www用户运行 19 $res_log = '-------------------------'.PHP_EOL; 20 $res_log .= $content['user_name'] . ' 在' . date('Y-m-d H:i:s') . '向' . $content['repository']['name'] . '项目的' . $content['ref'] . '分支push了' . $content['total_commits_count'] . '个commit:' . PHP_EOL; 21 $res_log .= $res.PHP_EOL; 22 file_put_contents("git-webhook.log", $res_log, FILE_APPEND);//追加写入 23 } else if ($content['ref']=='refs/heads/beta_v1.0.5' && $content['total_commits_count']>0) { 24 $res = shell_exec("cd {$path} && git pull 2>&1");//以www用户运行 25 $res_log = '-------------------------'.PHP_EOL; 26 $res_log .= $content['user_name'] . ' 在' . date('Y-m-d H:i:s') . '向' . $content['repository']['name'] . '项目的' . $content['ref'] . '分支push了' . $content['total_commits_count'] . '个commit:' . PHP_EOL; 27 $res_log .= $res.PHP_EOL; 28 file_put_contents("git-webhook.log", $res_log, FILE_APPEND);//追加写入 29 } 30 echo '更新成功:'.date('y-m-d H:i:s');