先贴配置

location /webhook {
        default_type text/plain;
        content_by_lua_block {
            -- 配置部分
            local repo_path = "/path/html"  -- 你的仓库本地路径
            local log_file = "/path/webhook.log"       -- 日志文件路径-- 记录日志函数
            local function log_message(message)
                local time = os.date("[%Y-%m-%d %H:%M:%S]")
                local file = io.open(log_file, "a")
                if file then
                    file:write(time .. " " .. message .. "\n")
                    file:close()
                end
            end
             
            -- 执行 git pull 命令
            local handle = io.popen("cd " .. repo_path .. " && git pull 2>&1")
            local result = handle:read("*a")
            handle:close()
             
            -- 记录执行结果
            log_message("Git pull result: " .. result)
             
            -- 返回执行结果
            ngx.say(result)
        }
    }

2025-06-15T02:15:16.png
需要在git配置文件url设置用户名密码
2025-06-15T02:18:01.png

使用CNB托管

#.cnb.yml
main:
  push:
    - stages:
        - name: webhook
          script: curl http://host/webhook

2025-06-15T02:21:48.png