webhook入门


 

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM