Skip to content

Instantly share code, notes, and snippets.

@litaonet
Forked from guweigang/gitlab_trigger.php
Created June 10, 2014 13:15
Show Gist options
  • Select an option

  • Save litaonet/bc6f657e7bc53755316e to your computer and use it in GitHub Desktop.

Select an option

Save litaonet/bc6f657e7bc53755316e to your computer and use it in GitHub Desktop.
<?php
$fs = fopen('./cycle_hook.log', 'a');
$client_ip = $_SERVER['REMOTE_ADDR'];
fwrite($fs, 'Request on ['.date("Y-m-d H:i:s").'] from ['.$client_ip.']'.PHP_EOL);
$json = file_get_contents('php://input');
$data = json_decode($json, true);
fwrite($fs, 'Data: '.print_r($data, true).PHP_EOL);
fwrite($fs, '======================================================================='.PHP_EOL);
$fs and fclose($fs);
// 執行上面所述的 update.sh
echo "<pre>";
echo shell_exec("/bin/sh ". __DIR__ . '/update.sh');
echo '</pre>';
/*
update.sh
#!/bin/bash
cd /home/work/source/git/vsfinance_cycle/ui/
/home/work/local/git/bin/git remote update -p
/home/work/local/git/bin/git checkout -f develop
/home/work/local/git/bin/git pull
cd /home/work/source/git/vsfinance_cycle/fe/
/home/work/local/git/bin/git remote update -p
/home/work/local/git/bin/git checkout -f dev
/home/work/local/git/bin/git pull
cd /home/work/source/git/vsfinance_cycle/skeleton/
/home/work/local/git/bin/git remote update -p
/home/work/local/git/bin/git checkout -f master
/home/work/local/git/bin/git pull
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment