配置碼雲git自動更新的webhook


 

配置項目提交到git的時候自動同步服務器代碼

一、在服務器項目跟目錄新建文件hook.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 /home/www/honli && git pull https://654589023%40qq.com:passwod@gitee.com/xxxx/xxxx.git 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文件中
}
?>

  

二、配置碼雲webhook:

 

 

三、確認服務器安裝了git,在web目錄下clone 項目:git clone https://gitee.com/xxxx/xxxx.git;

四、把git的目錄權限改為web用戶權限: chown -r www:www

五、手動更新代碼:cd /home/www/honli && git pull;

六、git pull 沖突或錯誤時,用命令git stash && git pull解決沖突或錯誤


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM