2017-10-28 8 views
2

Laravel에 간단한 배포자를 구축하려고합니다. WebHook을 받고, 배포를 수행하고, 배포에 대한 정보를 저장합니다.

나는 다음과 같은 수행 할 Laravel 5.2 작업 디스패처를 사용하고 다음 exec() 기능의

public function deploy() 
{ 
    $result = 0; 
    $output = array(); 
    exec('cd ' . $this->deploymentMapping->full_file_path . '; git pull', $output, $result); 
    return array(
     'result' => $result, 
     'output' => $this->outputToString($output) 
    ); 
} 

나의 이해이 직접 오류를 덤프하지 않아야하지만, $output에 저장하는 것입니다.

그러나 명령 줄에서 내 서버의 php artisan queue:work을 실행하면 작업 디스패처를 테스트하기 위해 즉시 명령 줄 출력에 fatal: Not a git repository (or any of the parent directories): .git이 덤프됩니다. 이 자식 오류는 올바른이지만, 마치 exec()이 오류를 던진 것처럼 작업이 "실패"합니다. 이 올바른지? 다음과 같이 내 직업은 자신의 방법으로 오류를보고해야한다 :

public function handle() 
{ 
    $deploymentAttempt = new DeploymentAttempt(); 
    $deploymentAttempt->deployment_id = $this->deploymentID; 
    $gitResponse = $this->deployer->deploy(); //the above function 
    $deploymentAttempt->success = !($gitResponse['result'] > 0); 
    $deploymentAttempt->message = $gitResponse['output']; 
    $deploymentAttempt->save(); 
} 

답변

1

PHP의 exec 별도로 stderr 출력을 캡처 할 수있는 간단한 방법을 제공하지 않기 때문입니다.

stderr도 캡처해야합니다.

stderr에서 stdout으로 리디렉션해야합니다. 2>&1을 명령 끝에 추가하십시오.

exec('cd ' . $this->deploymentMapping->full_file_path . '; git pull 2>&1', $output, $result); 

그것은 예상 출력과 키 어레이 당 한 줄 배열 $output을 채울 것이다.

this thread.

+0

감사를 따를 수 2>&1의 작동 방식에 대한 자세한 내용을 알고! 작업을 실패하게 만드는 오류는 실제로 StdOut/StdErr에서이 문제가 아니 었습니다. 실제로'$ deploymentAttempt-> successful'보다는'$ deploymentAttempt-> success'를 쓰는 것이 었습니다. 나는 딩고 야. 당신의 도움을 주셔서 감사합니다 :) – k4kuz0