跳到主要內容

發表文章

目前顯示的是 5月, 2023的文章

use slack to trigger CI

背景: CI server在特殊網段,規劃觸發CI的成員,無法連到該網段。原本規劃使用email,但是大部分免費的email,已經很難僅用帳密來設定讀取信件。因此規劃使用slack來觸發。 基本原理:CI server讀取slack特定channel的訊息,確定是新指令後,便觸發CI。 shellscrpit: # 讀取檔案目錄 dir=$(dirname "$0") echo "dir: $dir" latestTSPath="$dir/latestTS.txt" jarPath="$dir/get-slack-message-1.0.jar" lastlatestTS=$(cat $latestTSPath | cut -d ',' -f1) java -jar $jarPath ${Channel ID} ${BOT_TOKEN} > $latestTSPath latestTS=$(cat $latestTSPath | cut -d ',' -f1) arg1=$(cat $latestTSPath | cut -d ',' -f1) APP=$(cat $latestTSPath | cut -d ',' -f2) arg3=$(cat $latestTSPath | cut -d ',' -f3) Hash=$(cat $latestTSPath | cut -d ',' -f4) buildType=$(echo $arg3 | cut -d '_' -f1) logFile="$dir/distribute.log" echo "$(date '+%Y-%m-%d %H:%M:%S') lastest $arg1 $APP $arg3" >> $logFile if [[ "$lastlatestTS" != "$latestTS" ]] then echo "$(date '+%Y-%m-%d %H:%M:%S&