Back to Git/Gerrit

See Also rsyncPM2

Git and Gerrit Server Hooks

Git 和 Gerrit 服务器端钩子的配置说明。所谓的钩子(Hooks),是具有预定名称的脚本,它们在 Git 操作(例如,推送)之前或之后运行。

1. Git Server Hooks

https://aotu.io/notes/2017/04/10/githooks/index.html

1.1. 位置

git init --bare server.git
# server.git/hooks //存放在这里

1.2. 格式


2. Gerrit Server Hooks

$site_dir/hooks (site_dir is the directory containing /etc, /plugins, /db, /data...)

2.1. 格式

任意可执行的文件


参考脚本: https://github.com/wernight/gerrit-hooks-examples/blob/master/ref-update


3. EXAMPLES

3.1. node.js(rsync & pm2 deploy)

ref-update

# gerrrit server
//如果本版本库存在hooks/post-update,则执行
# git server
/var/lib/git_repo/web/SSAP.git/hooks/post-update

post-update

###1. rsync server to deploy server
rsync -avz /var/lib/git_repo/web/SSAP.git node@web_qa:/var/node_apps

###2. update workspace # git clone /var/lib/git_repo/web/SSAP.git ~/workspace/SSAP
cd ~/workspace/SSAP ||exit
unset GIT_DIR
git pull origin master

###3. pm2 deploy # depend on node
pm2 deploy ~/workspace/SSAP/ecosystem.config.js qa

###last
exec git update-server-info

4. Reference

MainWiki: git_and_gerrit_server_hooks (last edited 2017-12-15 00:46:40 by twotwo)