关于宝塔面板:项目推送到远程仓库后宝塔webhook自动发布

7次阅读

共计 1741 个字符,预计需要花费 5 分钟才能阅读完成。

一、服务器装置 git

装置命令
yum install git

已装置的能够查看 git 版本
git --version

我始终装置失败,不晓得什么起因,如果有大神晓得,请指教一二。
于是我就用如下步骤装置 git 了

1. 进入 git 官网


https://mirrors.edge.kernel.o…

2. 找到你须要的版本

3. 右键 gz 或者 xz,复制链接地址
4. wget+ 链接地址下载

wget https://www.kernel.org/pub/software/scm/git/git-2.35.1.tar.gz

5. 解压缩

tar -zxf git-2.35.1.tar.gz

6. 装置

进入文件夹:cd git-2.35.1
设置装置门路:./configure --prefix=/usr/local/
构建和装置:make && make install

7. 查看

git --version

git version 2.35.1

装置胜利

二、装置 webhook

三、点击设置 – 增加 – 输出名称和执行脚本

执行脚本如下,有两处须要批改
gitPath=”/www/wwwroot/$1″(留神你的阿里云文件门路,如果不一样须要批改)
gitHttp=”https://gitee.com/yourname/$1.git”(留神你的近程仓库地址,肯定要改)

#!/bin/bash
echo ""
#输入以后工夫
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#判断宝塔 WebHook 参数是否存在
if [! -n "$1"];
then 
          echo "param 参数谬误"
          echo "End"
          exit
fi
#git 我的项目门路
gitPath="/www/wwwroot/$1"
#git 网址
gitHttp="https://gitee.com/yourname/$1.git"
 
echo "Web 站点门路:$gitPath"
 
#判断我的项目门路是否存在
if [-d "$gitPath"]; then
        cd $gitPath
        #判断是否存在 git 目录
        if [! -d ".git"]; then
                echo "在该目录下克隆 git"
                git clone $gitHttp gittemp
                mv gittemp/.git .
                rm -rf gittemp
        fi
        #拉取最新的我的项目文件
        git reset --hard origin/master
        git pull
        #设置目录权限
        chown -R www:www $gitPath
        echo "End"
        exit
else
        echo "该我的项目门路不存在"
        echo "End"
        exit
fi

四、配置近程仓库

宝塔面板,关上 webhook 密钥

近程仓库,配置 WebHook

五、为了防止 git pull 输出用户名明码,先把用户名明码加上

cd /www/wwwroot/ 下   //cd 到你本人的目录
git clone https://gitee.com/yourname/ 本人的项目名称.git  

git config --global user.name "用户名"
git config --global user.email "邮箱"
git config --global credential.helper store

// 会生成.gitconfig 的文件,查看
cat ~/.gitconfig  // 显示内容

[user]
        name = 输出的用户名
        email = 输出的邮箱
[credential]
        helper = store
// 第一次 pull 会提醒输出用户名明码
git pull
Username for 'https://gitee.com': xxxx@xxxx.com
Password for 'https://xxxx@xxxx.com@gitee.com': 输出正确明码
// 生成.git-credentials 暗藏文件
cat ~/.git-credentials
https://Username:Password@gitee.com
 
vi ~/.git-credentials
可加多个用户名明码

最初,把网站根目录换成 dist 文件夹。

留神:如果宝塔面板上的网站根目录是 dist 文件夹,记得批改本地的.gitignore 文件


这样当你从本地仓库 git push master 到近程仓库之后,dist 文件夹代码就主动公布到线上了

查看 WebHook 日志

正文完
 0