405 宝塔钩子_宝塔面板webhook配合gitlab完成git钩子的搭建
寶塔面板webhook配合gitlab完成git鉤子的搭建
我們假設(shè)你了解了gitlab的webhook的設(shè)置。熟悉寶塔面板并會(huì)安裝寶塔webhook。
如果還沒掌握,請(qǐng)自行去了解。
一、在寶塔面板中的軟件中安裝”寶塔WebHook”
二、根據(jù)需求修改以下的文件。
#!/bin/bash
echo ""
#輸出當(dāng)前時(shí)間
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#判斷寶塔WebHook參數(shù)是否存在
if [ ! -n "$1" ];
then
echo "param參數(shù)錯(cuò)誤"
echo "End"
exit
fi
#git項(xiàng)目路徑
gitPath="/www/wwwroot/$1"
#git 網(wǎng)址
gitHttp="http://git.hxsen.com/houxin/$1.git"
echo "Web站點(diǎn)路徑:$gitPath"
#判斷項(xiàng)目路徑是否存在
if [ -d "$gitPath" ]; then
cd $gitPath
#判斷是否存在git目錄
if [ ! -d ".git" ]; then
echo "在該目錄下克隆 git"
sudo git clone $gitHttp gittemp
sudo mv gittemp/.git .
sudo rm -rf gittemp
fi
echo "拉取最新的項(xiàng)目文件"
#sudo git reset --hard origin/master
sudo git pull
echo "設(shè)置目錄權(quán)限"
sudo chown -R www:www $gitPath
echo "End"
exit
else
echo "該項(xiàng)目路徑不存在"
echo "新建項(xiàng)目目錄"
mkdir $gitPath
cd $gitPath
#判斷是否存在git目錄
if [ ! -d ".git" ]; then
echo "在該目錄下克隆 git"
sudo git clone $gitHttp gittemp
sudo mv gittemp/.git .
sudo rm -rf gittemp
fi
echo "拉取最新的項(xiàng)目文件"
#sudo git reset --hard origin/master
sudo git pull
echo "設(shè)置目錄權(quán)限"
sudo chown -R www:www $gitPath
echo "End"
exit
fi
這里注意幾個(gè)地方修改
1.gitPath的配置
gitPath就是你的網(wǎng)站的目錄
比如,我的網(wǎng)站的運(yùn)行目錄/www/wwwroot/blog,這里填寫/www/wwwroot/$1
其中。blog用$1代替,制作通用的git鉤子。
2.gitHttp這里是你git項(xiàng)目的地址,就是使用git面板。拉取git文件的地址。
比如,我的git服務(wù)路徑是http://git.hxsen.com/houxin/blog.git,
這里填寫的是http://git.hxsen.com/houxin/$1.git,同樣是為了做通用的設(shè)置。
在git鉤子中,我把項(xiàng)目名以變量的形式傳過來,就可以了。
如果你用了開放的git管理系統(tǒng)如,如gitee,你應(yīng)該這么寫
https://gitee.com/你的地址/$1.git
三、最后一步,就是獲取gitlab需要你填寫的url路徑了。
打開寶塔webhook,找到自己添加的任務(wù)。點(diǎn)擊”查看秘鑰”,就會(huì)出現(xiàn)以下信息
寶塔WebHook使用方法:
GET/POST:
http://110.28.36.47:8888/hook?access_key=CpQE4U6A3IxvkiedA58WBD8uDPNVlebNAMJe9toQjGdMTX7H¶m=aaa
@param access_key string HOOK密鑰
@param param string 自定義參數(shù)(在hook腳本中使用$1接收)
注意,這里的面板,是你登錄面板的地址。一般都不是80端口,請(qǐng)帶端口號(hào)。
比如:
120.149.215.141:8888
或者簡易版的去除參數(shù)。去除了自動(dòng)創(chuàng)建目錄的操作,測試正常運(yùn)行
代碼如下:
#!/bin/bash
echo ""
#輸出當(dāng)前時(shí)間
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#git項(xiàng)目路徑
gitPath="/www/wwwroot/shangyfy_test"
#git 網(wǎng)址
gitHttp="http://120.79.8.110:8090/web/test.git"
echo "Web站點(diǎn)路徑:$gitPath"
#判斷項(xiàng)目路徑是否存在
if [ -d "$gitPath" ]; then
cd $gitPath
#判斷是否存在git目錄
if [ ! -d ".git" ]; then
echo "在該目錄下克隆 git"
sudo git clone $gitHttp gittemp
sudo mv gittemp/.git .
sudo rm -rf gittemp
fi
echo "拉取最新的項(xiàng)目文件"
#sudo git reset --hard origin/master
sudo git pull
echo "設(shè)置目錄權(quán)限"
sudo chown -R www:www $gitPath
echo "End"
exit
fi
四、建議使用下面的更加的精簡的版本,對(duì)于敏感的操作,建議我們自己做。讓程序做簡單重復(fù)的工作就行
#!/bin/bash
echo ""
#輸出當(dāng)前時(shí)間
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#git項(xiàng)目路徑
gitPath="/www/wwwroot/hxsen"
#git 網(wǎng)址
gitHttp="https://gitee.com/hx-self/hxsen.git"
echo "Web站點(diǎn)路徑:$gitPath"
#判斷項(xiàng)目路徑是否存在
if [ -d "$gitPath" ]; then
cd $gitPath
echo "拉取最新的項(xiàng)目文件"
#sudo git reset --hard origin/master
sudo git pull
echo "設(shè)置目錄權(quán)限"
sudo chown -R www:www $gitPath
echo "End"
exit
fi
總結(jié)
以上是生活随笔為你收集整理的405 宝塔钩子_宝塔面板webhook配合gitlab完成git钩子的搭建的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java sax解析xml_【转】jav
- 下一篇: 计算机设备报废流程图,报废流程图.ppt