开源中国Git PUSH钩子部署PHP程序
阿神
阿神 2017-05-02 09:19:58
0
3
745

我的代码托管在开源中国得Git库里,想使用Git钩子来实现程序的部署,写了一个程序接受钩子的post的数据,但是不能实现程序的部署。。代码如下:

public function index(){
        $logger = new KLogger(LOG_PATH.'KLogger');

        $web_root_dir = APP_PATH;  // /var/www/site

        if(IS_POST){
            $payload = $_POST;
            $payload = json_decode($payload['hook']);
            $logger->info('data from git post...', $payload); 

            // if (!empty($payload['password'])){
                $command = "cd {$web_root_dir} && git pull";
                $logger->info('enter if .....');
                $result = exec($command);
                $logger->info('command execute result...'.$result); 

            // }
        }

    }

在程序里记录了日志,能接收到post数据,但是命令执行不成功,下面是log的内容:

[2015-05-05 2:07:34.114928] [INFO] data from git post...
    password: '123456'
    push_data: stdClass::__set_state(array(
         'before' => '7a563d4498371a8572a88ff22fb726ac7f8dd467',
         'after' => 'f24b208ddb520b1349fca6a5a0295db516b3982b',
         'ref' => 'refs/heads/master',
         'user_id' => 120469,
         'user_name' => '',
         'repository' => stdClass::__set_state(array(
             'name' => '',
             'url' => '',
             'description' => '',
             'homepage' => '',
        )),
         'commits' => array(
            0 => stdClass::__set_state(array(
                 'id' => 'f24b208ddb520b1349fca6a5a0295db516b3982b',
                 'message' => 'a',
                 'timestamp' => '2015-05-05T02:07:35+08:00',
                 'url' => 'http://git.oschina.net/commit/f24b208ddb520b1349fca6a5a0295db516b3982b',
                 'author' => stdClass::__set_state(array(
                     'name' => '',
                     'email' => '',
                )),
            )),
        ),
         'total_commits_count' => 1,
    ))
[2015-05-05 2:07:34.115142] [INFO] enter if .....
[2015-05-05 2:07:35.482580] [INFO] command execute result...
阿神
阿神

闭关修行中......

모든 응답(3)
漂亮男人

http://blog.skyx.in/archives/158/

권한 문제일 수도 있습니다

漂亮男人

저는 일반적으로 후크를 사용하지 않습니다. 배포가 필요할 때마다 이 스크립트를 실행합니다.

으아아아

물론, 프로그램이 코드 업데이트를 위해 다른 작업도 수행해야 하는 경우 이는 유용하지 않습니다.

左手右手慢动作

내가 작성한 간단한 작은 스크립트를 게시하면 일부 정보를 구성하면 토픽 기능을 구현할 수 있을 뿐만 아니라 해당 정보를 로그에 간단히 기록할 수도 있습니다.

으아아아
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!