gitlab+webhook
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gitlab+webhook相关的知识,希望对你有一定的参考价值。
<?php
#项目 $project = trim($_GET[‘project‘]); if (empty($project)) { return json_encode([‘msg‘ => "project not exist."]); } #你的项目地址 $wwwFile = ‘/server/webroot/‘ . $project . ‘/‘;
#钩子日志 $fs = fopen(‘./hooks.log‘, ‘a‘); fwrite($fs, ‘================ Update Start ===============‘ . PHP_EOL . PHP_EOL); $accessToken = ‘QhNO8YHqym5PHQQsexapF7041xOhzm62DRH‘;
#白名单服务器执行ip $accessIp = [‘192.168.0.174‘, ‘192.168.2.204‘, ‘192.168.3.222‘]; $clientToken = trim($_GET[‘token‘]); $clientIp = $_SERVER[‘REMOTE_ADDR‘]; fwrite($fs, ‘Request on [‘ . date("Y-m-d H:i:s") . ‘] from [‘ . $clientIp . ‘]‘ . PHP_EOL); #密匙验证 if ($clientToken !== $accessToken) { fwrite($fs, "Invalid token [{$clientToken}]" . PHP_EOL); return json_encode([‘msg‘ => "error 403"]); } #ip白名单验证 if (!in_array($clientIp, $accessIp)) { fwrite($fs, "Invalid ip [{$clientIp}]" . PHP_EOL); return json_encode([‘msg‘ => "error 503"]); } //命令执行$output = shell_exec("cd {$wwwFile} && git stash && git pull && chown nginx. ./* -R 2>&1");
fwrite($fs, ‘Info:‘ . $output . PHP_EOL); fwrite($fs, PHP_EOL . ‘================ Update End ===============‘ . PHP_EOL . PHP_EOL);
$fs and fclose($fs);
以上是关于gitlab+webhook的主要内容,如果未能解决你的问题,请参考以下文章
jenkins系列3-gitlab webhook,jenkins自动构建
jenkins系列3-gitlab webhook,jenkins自动构建