前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >配置码云git自动更新的webhook

配置码云git自动更新的webhook

作者头像
双面人
发布2019-10-26 16:04:25
1.2K0
发布2019-10-26 16:04:25
举报
文章被收录于专栏:热爱IT热爱IT

配置项目提交到git的时候自动同步服务器代码

一、在服务器项目跟目录新建文件hook.php 代码如下:

代码语言:javascript
复制
<?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解决冲突或错误

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档