实现:向Gitlab提交代码的时候,通过钩子同步到测试服务器。
总共分两步,代码和Gitlab钩子配置
第一步代码部分:
<?php
/**
* Created by PhpStorm.
* User: Genghai_Y
* Date: 2020/9/29
* Time: 17:13
*/
$project = trim($_GET['project']);
$dev = trim($_GET['dev']);
if (empty($project)) {
die('project not exist.');
}
//网站目录
$www_file='/data/www/' . $project . '/';
//打开网站目录下的hooks.log文件 需要在服务器上创建 并给写权限
$fs = fopen('../hooks.log', 'a');
fwrite($fs, '================ Update Start ==============='.PHP_EOL.PHP_EOL);
//自定义字串掩码 用于验证
$access_token = 'c55f84323297bfdd28ca584e6fa73a78';
//接受的ip数组,也就是允许哪些IP访问这个文件 这里是gitlab服务器IP
$access_ip = array('8.8.8.8', 'xxx.xxx.xxx.xxx');
//获取请求端的ip和token
$client_token = $_GET['token&#