通過寶塔webhook,實現git自動拉取服務器代碼


1、寶塔安裝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="/你的路徑/$1"
#git 網址
gitHttp="https://gitee.com/你的地址/$1.git"
echo "Web站點路徑:$gitPath"
#判斷項目路徑是否存在
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 "拉取最新的項目文件"
        #sudo git reset --hard origin/master
        sudo git pull        
        echo "設置目錄權限"
        sudo chown -R www:www $gitPath
        echo "End"
        exit
else
        echo "該項目路徑不存在"
                echo "新建項目目錄"
        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 "拉取最新的項目文件"
        #sudo git reset --hard origin/master
        sudo git pull
        echo "設置目錄權限"
        sudo chown -R www:www $gitPath
        echo "End"
        exit
fi

 

 2、查看API秘鑰,得到你訪問的網址。 

 

 

 3、前往git服務器項目,管理里面添加webhook,值為剛剛生成的網址。

 

 

當然,首先你服務器得裝了git。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM