网页自动化部署(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,开启导致配置不成功,不知道为什么。

以上配置完成,即可。

相关推荐
zkmall1 小时前
企业电商解决方案哪家好?ZKmall模块商城全渠道支持 + 定制化服务更省心
大数据·运维·重构·架构·开源
绝不偷吃3 小时前
ELK日志分析系统
运维·elk·jenkins
朱包林4 小时前
day45-nginx复杂跳转与https
linux·运维·服务器·网络·云计算
孙克旭_4 小时前
day045-nginx跳转功能补充与https
linux·运维·nginx·https
Hacker_Oldv6 小时前
软件测试(功能、工具、接口、性能、自动化、测开)详解
运维·自动化
Java樱木6 小时前
使用字节Trae + MCP,UI 到网页自动化。
运维·自动化
无敌暴龙兽z9 小时前
离线环境安装elk及设置密码认证
运维·elk
好奇的菜鸟9 小时前
如何在 Ubuntu 24.04 (Noble) 上使用阿里源
linux·运维·ubuntu
bcbobo21cn9 小时前
初步了解Linux etc/profile文件
linux·运维·服务器·shell·profile
wayuncn10 小时前
月付物理服务器租用平台-青蛙云
运维·服务器·服务器租用·服务器托管·物理机租用