github: https://github.com/adnanh/webhook
webhook 持續集成
hooks.json
[ { "id": "redeploy-webhook", "execute-command": "/home/work/redeploy.sh", "include-command-output-in-response":true, "include-command-output-in-response-on-error":true, "command-working-directory": "/home/work/demo" } ]
redeploy.sh
#!/bin/sh echo "Hello world!" cd /projects/demo git pull https://username:password@github.com/adnanh/webhook.git branch
增加執行權限
chmod +x redeploy.sh
啟動
./webhook -hooks hooks.json -port=8081 -verbose
本地倉庫判斷遠程倉庫是否有更新,shell腳本定時更新
#!/bin/bash # 進入項目目錄 cd /projects/demo # 獲取遠程倉庫branch分支版本哈希值 remote_hash=`git ls-remote https://username:password@github.com/adnanh/webhook.git branch | awk '{ print $1}'` # 獲取本地倉庫branch分支版本哈希值 local_hash=`git rev-parse HEAD` if [ "$remote_hash" != "$local_hash" ];then echo "remote results are: $remote_hash" echo "local results are: $local_hash" # 獲取最新版本 git pull https://username:password@github.com/adnanh/webhook.git branch # 重啟服務器 bin/supervisorctl -c /etc/supervisord.conf restart demo fi
crontab -e 進行定時
*/1 * * * * /projects/demo/deploy/demo_ci.sh >> /projects/demo/deploy/demo_ci.log 2>&1