Server docking code cloud webhooks realize automatic deployment

little bottle
Release: 2023-04-06 07:36:02
forward
3593 people have browsed it

The main content of this article is about allowing the server to connect to the code cloud webhooks to achieve automatic deployment. It has certain reference value. Interested friends can learn about it.

The Code Cloud WebHook function is to help users push code and automatically call back an http address you set.

Service installation git

php code (must be accessible from the external network)


<?php
//本地路径滚adminasdfdasfasdf
$file = "/wwwroot/webhooksLog.txt";
$_File = fopen($file, "a+");
$local = &#39;/wwwroot/test&#39;;
//仓库地址
$remote = &#39;远程仓库地址&#39;;
 
//密码
$password = &#39;123456&#39;;
 
//获取请求参数
$request = file_get_contents(&#39;php://input&#39;);
if (empty($request)) {
  die(&#39;请求参数为空&#39;);
}
 
//验证密码是否正确
$data = json_decode($request, true);
if ($data[&#39;password&#39;] != $password) {
  die(&#39;密码错误&#39;);
}
fwrite($_File, "************************************************\r\n");
fwrite($_File, "推送人Name: ");
fwrite($_File, $data["pusher"]["name"] . "\r\n");
fwrite($_File, "推送人Email: ");
fwrite($_File, $data["pusher"]["email"] . "\r\n");
fwrite($_File, "推送人UserName: ");
fwrite($_File, $data["pusher"]["username"] . "\r\n");
fwrite($_File, "推送人备注: ");
fwrite($_File, $data["head_commit"]["message"] . "\r\n");
fwrite($_File, "推送项目: ");
fwrite($_File, $data["repository"]["full_name"] . "\r\n");
fwrite($_File, "推送分支: ");
fwrite($_File, $data["ref"] . "\r\n");
fwrite($_File, "推送日期: ");
fwrite($_File, $data["head_commit"]["timestamp"] . "\r\n");
fwrite($_File, "************************************************\r\n");
fclose($_File);
//return;
//echo shell_exec("cd {$local} && git pull {$remote} 2>&1");
system(&#39;cd &#39;.$local.&#39; && "C:/Program Files/Git/cmd/git.exe" pull &#39;.$remote.&#39; 2>&1&#39;, $out);
echo $out;
die(&#39;done&#39; . date(&#39;Y-m-d H:i:s&#39;));
?>
Copy after login

fill Enter the domain name and click submit

Complete

Related tutorials:PHP video tutorial

The above is the detailed content of Server docking code cloud webhooks realize automatic deployment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!