网页自动化部署(webhook方法)

实现步骤:

  1. 宝塔安装宝塔WebHook 2.5插件。

  2. github 上配置网页仓库(或可在服务器的网页根目录clone)。

  3. 配置宝塔WebHook 2.5

    • 添加hook脚本;

    • 编辑添加syncJC脚本;
bash 复制代码
#!/bin/bash
# 定义网站根目录
WEBROOT="/www/wwwroot/jessi53"
# 定义日志文件路径
LOGFILE="/www/server/panel/plugin/webhook/log/webhook.log"

# 设置 HOME 环境变量
export HOME=/root

# 将调试信息写入日志文件
echo "[$(date)] Webhook triggered. Starting deployment process..." >> $LOGFILE

# 切换到网站根目录
echo "[$(date)] Switching to directory: $WEBROOT" >> $LOGFILE
cd $WEBROOT

# 设置 Git 安全目录
echo "[$(date)] Setting Git safe directory: $WEBROOT" >> $LOGFILE
git config --global --add safe.directory $WEBROOT >> $LOGFILE 2>&1
git config --system --add safe.directory $WEBROOT >> $LOGFILE 2>&1

# 检查是否是 Git 仓库
if [ -d "$WEBROOT/.git" ]; then
    echo "[$(date)] Fetching latest changes from GitHub..." >> $LOGFILE
    git fetch origin >> $LOGFILE 2>&1
    echo "[$(date)] Resetting local branch to match remote branch..." >> $LOGFILE
    git reset --hard origin/main >> $LOGFILE 2>&1
else
    echo "[$(date)] Initializing Git repository and pulling latest changes..." >> $LOGFILE
    git init >> $LOGFILE 2>&1
    git remote add origin https://github.com/Jsvi53/jessi53.git >> $LOGFILE 2>&1
    git fetch origin >> $LOGFILE 2>&1
    git reset --hard origin/main >> $LOGFILE 2>&1
fi

# 设置目录权限
echo "[$(date)] Setting permissions for: $WEBROOT" >> $LOGFILE
chown -R www:www $WEBROOT >> $LOGFILE 2>&1

# 将请求体写入日志文件
echo "[$(date)] Webhook triggered. Pulled latest changes from GitHub." >> $LOGFILE

注意,网站的根目录为jessi53。

以上,宝塔上webhook配置完毕,可点击测试进行测试,然后查看log

  1. 配置github 上的 WebHooks:

开启ssl,开启导致配置不成功,不知道为什么。

以上配置完成,即可。

相关推荐
jerryinwuhan8 小时前
《系统部署与运维》开篇 课程介绍
运维
科技绘图10 小时前
快鲸GEO vs 传统AI搜索优化:全链路自动化与高效内容生产在转化闭环上的对比
数据库·人工智能·自动化
我是谁??10 小时前
Ubuntu22.04更换清华源
linux·运维·服务器
Shell运维手记11 小时前
Linux 常用基础命令学习笔记
linux·运维·笔记·学习·算法·github
朴马丁11 小时前
国际与国产PLM在精细化工赛道的布局:2026年主要厂商技术特色
大数据·运维·人工智能·流程行业plm·化工新材料
Elastic 中国社区官方博客12 小时前
Elasticsearch:使用 AI Agent 来创建 workflow
大数据·运维·人工智能·elasticsearch·搜索引擎·自动化·全文检索
测试运维日常笔记12 小时前
Linux系统安装配置TigerVNC服务器完整指南
linux·运维·服务器
喜欢的名字被抢了13 小时前
程序出问题怎么查,以及如何让它不掉线
java·运维·数据库
雾时之林13 小时前
Linux----cron定时服务
linux·运维·服务器
壹玖玖肆14 小时前
医院后勤智能运维系统实用性评测
运维