/webhook

实现git钩子自动更新发布的脚本

Primary LanguagePHP

git webhook

git的钩子实现 ##Configuration 修改config.php

$_config_data["test"]  每一组都是一个站点,你可以多加几个站点
比如
$_config_data["new"] = array();
 $_config_data["new"]["access_token"] = "secret-token";//密钥
 $_config_data["new"]["access_ip"] = array("192.168.2.18");//允许ip
 $_config_data["new"]["dir"] = "/home/wwwys/test/webhook/";//目录必填
 $_config_data["new"]["git_url"] = "git@192.168.2.18:czw/test.git";//git地址
 $_config_data["new"]["sh_clone"] = "git clone {$_config_data["test"]["git_url"]} {$_config_data["test"]["dir"]}";//git clone 命令 初次发布必填
 $_config_data["new"]["sh_pull"] = "cd {$_config_data["test"]["dir"]} && /usr/bin/git pull"; //git pull 命令 更新代码必填

###web server open_basedir路径相对于需要发布的项目路径更高一级,不然php无法判断跨范围文件是否存在

##On GitHub | GitLab | Bitbucket

GitHub

In your repository, navigate to Settings → Webhooks → Add webhook, and use the following settings:

  • Payload URL: https://www.yoursite.com/webhook/index.php?k=new
  • k 参数是你配置的数组key值
  • Content type: application/json
  • Secret: The value of TOKEN in config.php
  • Which events would you like to trigger this webhook?: 🔘 Just the push event
  • Active: ☑️

Click "Add webhook" to save your settings, and the script should start working.

Example screenshot showing GitHub webhook settings

GitLab

In your repository, navigate to Settings → Integrations, and use the following settings:

Click "Add webhook" to save your settings, and the script should start working.

Example screenshot showing GitLab webhook settings

Bitbucket

In your repository, navigate to Settings → Webhooks → Add webhook, and use the following settings:

Click "Save" to save your settings, and the script should start working.

Example screenshot showing Bitbucket webhook settings