直接貼Shell傍念,這個只是用來方便查看和復(fù)制苏潜。
## !/bin/sh
## 項目名
TARGET_NAME=XXXX
## Scheme名
SCHEME=XXXX
##=======================
## 編譯類型
BUILD_TYPE=Release
## 當(dāng)前目錄
SORCEPATH=${WORKSPACE}
## workspace名
SPACE=${WORKSPACE}/${TARGET_NAME}.xcworkspace
##xcarchive文件的存放路徑
ARCHIVEPATH=$SORCEPATH/build/$SCHEME.xcarchive
## ipa文件的存放路徑
EXPORTPATH=$SORCEPATH/build/$SCHEME
## ExportOptions.plist文件的存放路徑
EXPORTOPTIONSPLIST=$SORCEPATH/build/ExportOptions.plist
## 導(dǎo)出后的ipa路徑
EXPORTPATHIPA=$SORCEPATH/build/$SCHEME/$SCHEME.ipa
echo -e "============First Build Clean============"
## 清理緩存
xcodebuild clean -workspace $SPACE -scheme ${SCHEME} -configuration ${BUILD_TYPE}
echo -e "============Build Clean============"
## 輸出關(guān)鍵信息
echo -e " TARGET_NAME : ${TARGET_NAME}"
echo -e " BUILD_TYPE : ${BUILD_TYPE}"
echo -e " SORCEPATH : ${SORCEPATH}"
echo -e " ARCHIVEPATH : ${ARCHIVEPATH}"
echo -e " EXPORTPATH : ${EXPORTPATH}"
echo -e " EXPORTOPTIONSPLIST : ${EXPORTOPTIONSPLIST}"
echo -e "============Build Archive============"
## 導(dǎo)出archive包
xcodebuild archive -workspace ${SPACE} -scheme ${SCHEME} -archivePath $ARCHIVEPATH
echo -e "============Build Archive Success============"
echo -e "============Export IPA============"
## 導(dǎo)出IPA包
xcodebuild -exportArchive -archivePath $ARCHIVEPATH -exportPath ${EXPORTPATH} -exportOptionsPlist ${EXPORTOPTIONSPLIST}
echo -e "============Export IPA SUCCESS============"
## 編譯完成時間 20181030_0931
BUILD_DATE="$(date +'%Y%m%d_%H%M')"
## info.plist路徑
PROJECT_INFOPLIST_PATH="${SORCEPATH}/${TARGET_NAME}/Info.plist"
## 取版本號
BUNDLESHORTVERSION=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${PROJECT_INFOPLIST_PATH}")
## 取build值
VERSION=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${PROJECT_INFOPLIST_PATH}")
## ipa更名規(guī)則 項目名V版本_年月日_時分
IPANAME="${TARGET_NAME}V${BUNDLESHORTVERSION}_${BUILD_DATE}.ipa"
## 更名后ipa路徑
EXPORTPATHNEWIPA=$EXPORTPATH/$IPANAME
echo -e "============Export end :${BUILD_DATE}============"
echo -e "============IPA Old Name: ${EXPORTPATHIPA}============"
echo -e "============IPA New Name: ${EXPORTPATHNEWIPA}============"
## IPA更名
cp $EXPORTPATHIPA $EXPORTPATHNEWIPA
echo -e "============Create New Name Success============"
## 刪除老IPA
rm $EXPORTPATHIPA
echo -e "============Delete Old Name Success============"