使用git HOOK自动部署git命令执行不成功
git@OSC上,使用PUSH钩子,每次push就通过URL访问项目下面的自动部署php文件
<code> header("Content-type: text/html; charset=utf-8"); $js=json_decode($_REQUEST["hook"]);//json转换 if($js->password!="xxxxxx")die("ERROR!");//判断密码 $fp=fopen("./log.txt",'a'); $lastcommit=$js->push_data->commits[count($js->push_data->commits)-1];//获取最后的commit if(strstr($lastcommit->message,"release"))//这里意为:如果最后的commit包含"release"则进行自动发布。 { exec('cd /home/xxx/');//进入目录 exec("git pull origin master");//进行git拉取,前提是使用了ssh fwrite($fp,"!!!".date('Y-m-d H:i:s')."\t".$lastcommit->message."\t".$lastcommit->author->name."\t"."Y"."\n");//进行记录 } else { fwrite($fp,date('Y-m-d H:i:s')."\t".$lastcommit->message."\t".$lastcommit->author->name."\t"."N"."\n"); } </code>
每次push后,项目下面的log.text确实有记录,但是代码没更新,还是得每次都手动git pull一下。这该如何是好啊?
回复内容:
git@OSC上,使用PUSH钩子,每次push就通过URL访问项目下面的自动部署php文件
<code> header("Content-type: text/html; charset=utf-8"); $js=json_decode($_REQUEST["hook"]);//json转换 if($js->password!="xxxxxx")die("ERROR!");//判断密码 $fp=fopen("./log.txt",'a'); $lastcommit=$js->push_data->commits[count($js->push_data->commits)-1];//获取最后的commit if(strstr($lastcommit->message,"release"))//这里意为:如果最后的commit包含"release"则进行自动发布。 { exec('cd /home/xxx/');//进入目录 exec("git pull origin master");//进行git拉取,前提是使用了ssh fwrite($fp,"!!!".date('Y-m-d H:i:s')."\t".$lastcommit->message."\t".$lastcommit->author->name."\t"."Y"."\n");//进行记录 } else { fwrite($fp,date('Y-m-d H:i:s')."\t".$lastcommit->message."\t".$lastcommit->author->name."\t"."N"."\n"); } </code>
每次push后,项目下面的log.text确实有记录,但是代码没更新,还是得每次都手动git pull一下。这该如何是好啊?
<code>exec('cd /home/xxx/');//进入目录 exec("git pull origin master");//进行git拉取,前提是使用了ssh </code>
在一个exec连在一起写吧,cd不会修改父进程所在目录,另外最好把输出重定向到文件方便排查。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development

How do you parse and process HTML/XML in PHP?

PHP Program to Count Vowels in a String

Delphi Digital: How to change the new AI economy by parsing the new ElizaOS v2 architecture?
