zoukankan      html  css  js  c++  java
  • 码云配置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解决冲突或错误

    宝塔使用WebHook

    在软件管理中下载宝塔WebHook添加如下脚本

    #!/bin/bash
    echo ""
    #输出当前时间
    date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
    echo "Start"
    #git项目路径
    gitPath="/data/www/wwwroot/httpurl/"
    #git 网址
    gitHttp="https://gitee.com/giturl"
    
    echo "Web站点路径:$gitPath"
    
    #判断项目路径是否存在
    if [ -d "$gitPath" ]; then
            cd $gitPath
            #判断是否存在git目录
            if [ ! -d ".git" ]; then
                    echo "在该目录下克隆 git"
                    git clone $gitHttp gittemp
                    mv gittemp/.git .
                    rm -rf gittemp
            fi
            #拉取最新的项目文件
            git reset --hard origin/master
            git pull
            #设置目录权限
            chown -R www:www $gitPath
            echo "End"
            exit
    else
            echo "该项目路径不存在"
            echo "End"
            exit
    fi

    Git配置如上(待完善)

    转载:https://www.cnblogs.com/mayi168/p/9070505.html

  • 相关阅读:
    关键性点位
    【转】Chrome——F12 谷歌开发者工具详解
    LPR-贷款市场报价利率
    盘口-挂单
    看盘
    复盘
    2020超星尔雅后台挂课工具(完全免费)
    Codeup 问题 D: String Subtraction (20)
    维瓦尔第协奏曲《四季》赏析 (Antonio Vavildi 《The Four Seasons》)
    算法4-5:求子串位置的定位函数
  • 原文地址:https://www.cnblogs.com/xuanjiange/p/11806488.html
Copyright © 2011-2022 走看看