码云 gitweb hook

服务器环境:CentOS 8.2.2004
项目目录: /www/wwwroot/www (www变量,自定义)
远程git版本库: 码云

步骤:

1. 准备工作

宝塔自带 git,没有的话可以自行安装

安装命令
yum install git

已安装的可以查看git版本
git --version

添加密钥到码云

ssh-keygen -t rsa

把id_rsa.pub全部字符串复制添加到码云部署项目公钥设置里边

 

为了避免git pull 输入用户名密码,先把用户名密码加上,此处可以自行使用公共KEY方式

cd /www/wwwroot/ 下   //使用git克隆
git clone https://gitee.com/isu5cn/自己的项目名称.git  //码云里有克隆链接,避免出现错误,使用https方式

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会提示输入用户名密码
[root@iZ25mi9h7ayZ test]# 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
可加多个用户名密码

2.宝塔面板 安装 宝塔 webhook

执行脚本代码

 

#!/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/isu5cn/$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

编辑框输入的命令会被过滤,点击编辑重新添加shell命令进去保存,需要使用命令重启宝塔

/etc/init.d/bt restart
Stopping Bt-Tasks...    done
Stopping Bt-Panel...    done
Starting Bt-Panel....   done
Starting Bt-Tasks...    done

 

http://ip:端口/hooks?access_key=密钥&param=git项目名
网站项目名需跟码云的项目名保持一致
上述地址添加到码云

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值