主页

提交代码到远程GIT仓库,代码自动同步到远程服务器上。

誮惜颜   IP属地: 青海
0 点赞 0阅读 1634

一.拉取代码PHP脚本,注意该脚本一定能外网访问

<?php
 
//本地路径
$local = 'C:\Users\Administrator\Desktop\testmonsoont';
//仓库地址
$remote = 'https://gitee.com/showlb/monsoons.git';
 
//密码
$password = '123456';
 
//获取请求参数
$request = file_get_contents('php://input');

if (empty($request)) {
    die('request is empty');
}
 
//验证密码是否正确
$data = json_decode($request, true);
if ($data['password'] != $password) {
    die('password is error');
}
 
echo shell_exec("cd {$local} && git pull {$remote} 2>&1");

die('done ' . date('Y-m-d H:i:s', time()));

二.配置gitee码云的webhooks(注意选择事件,选择push,意思是当提交推送的时候执行我们的脚本请求链接地址)


© 著作权归作者所有,转载或内容合作请联系作者