Jenkins自動(dòng)打包配置uniapp工程執(zhí)行腳本

背景

  • uniapp配置離線工程時(shí),需要把www打包資源文件拷貝到iOS/Android相應(yīng)的路徑下,才能完成離線工程打包。其中,iOS/Android放置www資源文件路徑如下:
    iOS:/Pandora/apps/__UNI__xxxxxxx/
    Android:/app/src/assets/apps/__UNI__xxxxxxx/

  • uniapp配置文件manifest.json
    該配置文件提供了包括平臺(tái),版本號(hào),前端入口路徑,各種key值等。

打包流程

  • 由于打包的時(shí)候,常見(jiàn)的輸入?yún)?shù)包括:分支名稱(默認(rèn)為master),版本名稱(versionName)和版本號(hào)(versionCode)。
    分支名稱可以參考文章:shell腳本和jenkins的“Jenkins Branches to build切分支”

  • 針對(duì)版本名稱和版本號(hào)進(jìn)行比較和替換(見(jiàn)后面腳本)

  • unaipp需要通過(guò)cli語(yǔ)言(腳手架語(yǔ)言)改造,才能適合自動(dòng)化打包。最后打包完之后,生成www資源文件,用于在一個(gè)工程的使用(即原生工程打包)。

腳本

rm -rf dist/build

# check versionName/versionCode
versionName="versionName"
versionCode="versionCode"
dir=`pwd`
file=$dir"/src/manifest.json"
echo "file:"$file

newName=$version_name
newCode=$version_code
nameNo=`grep $versionName $file`
echo "versionName: "$nameNo
codeNo=`grep $versionCode $file`
echo "versionCode: "$codeNo

currentName=`echo "${nameNo}" | sed -r "s/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/g"`
echo "currentName:"$currentNamever

currentCode=`echo "${codeNo}" | tr -cd "[0-9]"`
echo "currentCode:"$currentCode

if [ $currentName == $newName ]; then
    echo "get same name"
else
    echo "get different name"
    
    sed -i '' "s/$currentName/$newName/g" $file
fi

if [ $currentCode == $newCode ]; then
    echo "get same code"
else
    echo "get different code"
    
    sed -i '' "s/$currentCode/$newCode/g" $file
fi

#exit 0 #test
#check end

#檢查npm庫(kù)安裝
npm install

#編譯h5
npm run build-master:h5

cd dist/build/
zip -q -r app-demo-h5.zip h5

cd ../..
#編譯APP打包資源
npm run build-master:app-plus

mv dist/build/app-plus dist/build/www

  • 說(shuō)明:
sed -r "s/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/g"

通過(guò)正則表達(dá)式獲取諸如4.07.20的字符串。
其中.表示以.分割;[0-9]表示匹配數(shù)字0到9的任何一個(gè);+表示若干個(gè)(可以是1個(gè),也可以是多個(gè))

tr -cd "[0-9]"

通過(guò)tr語(yǔ)句獲取一個(gè)完整且連續(xù)的數(shù)字序列,比如40720。
這里其實(shí)也可以使用上面sed語(yǔ)句來(lái)處理。

sed -i '' "s/$currentName/$newName/g" $file

在file文件中使用newName替換currentName字符串。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容