具體內(nèi)容如下
build.sh:
#! bin/bash
###############使用方法
#1、build.sh和build.plist放入項(xiàng)目工程目錄
#2洞渤、命令行進(jìn)入目錄直接執(zhí)行:sh build.sh
export LC_ALL=zh_CN.GB2312;
export LANG=zh_CN.GB2312
###############設(shè)置
gitPath="https://xxx/xxx.git"
buildConfig="DevQA" #編譯的方式, 如Release,Debug等
isWorkSpace=true #判斷是用的workspace還是直接project,workspace設(shè)置為true坠陈,否則設(shè)置為false
projectName=`find . -name *.xcodeproj | awk -F "[/.]" '{print $(NF-1)}'` #項(xiàng)目名稱
###############編譯目錄
buildRootDir=~/Desktop/$projectName-IPA #ipa蜕企,icon最后所在的目錄絕對(duì)路徑
if [ -d "$buildRootDir" ]; then
echo $buildRootDir
else
echo "文件目錄不存在"
mkdir -pv $buildRootDir
echo "創(chuàng)建${buildRootDir}目錄成功"
fi
###############拉取代碼暗挑,
cd $buildRootDir
rm -rf ./build
mkdir build
buildProgressDir=$buildRootDir/build #打包過(guò)程目錄
cd $buildProgressDir
git clone ${gitPath}
projectDir=$buildProgressDir/$projectName #項(xiàng)目所在目錄的絕對(duì)路徑
echo $projectDir
exportPlist=$projectDir/build.plist #build.plist路徑
archivePath=$buildProgressDir/${projectName}.xcarchive #xcarchive路徑
###############獲取版本號(hào),bundleID
infoPlist="$projectDir/$projectName/SupportingFiles/Info.plist"
bundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $infoPlist`
bundleIdentifier=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $infoPlist`
bundleBuildVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $infoPlist`
###############開(kāi)始編譯app
cd $projectDir
if $isWorkSpace ; then #判斷編譯方式
echo "*****開(kāi)始編譯 workspace*****"
xcodebuild -target ${projectName} -configuration ${buildConfig} -sdk iphoneos clean SYMROOT=$buildProgressDir
xcodebuild archive -workspace $projectName.xcworkspace -scheme $projectName -archivePath ${archivePath}
else
echo "*****開(kāi)始編譯 project*****"
xcodebuild -target $projectName -configuration $buildConfig clean build SYMROOT=$buildProgressDir
xcodebuild archive -project $projectName.xcodeproj -scheme $projectName -archivePath ${archivePath}
fi
#判斷編譯結(jié)果
if test $? -eq 0
then
echo "*****編譯成功*****"
else
echo "*****編譯失敗*****"
exit 1
fi
###############開(kāi)始打包成.ipa
appDir=$buildProgressDir/$findFolderName #app所在路徑
echo "開(kāi)始打包${archivePath}至$buildProgressDir....."
xcodebuild -exportArchive -archivePath $archivePath -exportPath $buildProgressDir -exportOptionsPlist $exportPlist
###############檢查文件是否存在確認(rèn)打包成功
exportIpaPath=$buildProgressDir/$projectName.ipa
if [ -f "$exportIpaPath" ]
then
echo "$exportIpaPath 生成成功."
else
echo "打包失敗."
exit 1
fi
###############復(fù)制文件到主目錄
finalIPAPath=${buildRootDir}/${projectName}-$(date +%Y%m%d_%H%M).ipa
cp -f -p $exportIpaPath $finalIPAPath #拷貝ipa文件
echo "復(fù)制$ipaName.ipa到${finalIPAPath}成功"
echo "*****結(jié)束編譯困乒,處理成功*****"
#open $buildRootDir
###############上傳到蒲公英蝗肪,{uKey}袜爪,{_api_key}需替換
export LANG=en_US
export LC_ALL=en_US;
echo "正在上傳到蒲公英...."
curl -F "file=@$finalIPAPath" -F "uKey={uKey}" -F "_api_key={_api_key}" http://www.pgyer.com/apiv1/app/upload
#判斷上傳結(jié)果
if test $? -eq 0
then
echo "*****\^o^/*****上傳到蒲公英成功*****\^o^/*****"
else
echo "*****\(╯-╰)/*****上傳到蒲公英失敗*****\(╯-╰)/*****"
exit 1
fi
###############刪除構(gòu)建目錄
rm -rf $buildProgressDir
build.plist:
teamID:可登錄https://developer.apple.com/account 登錄相應(yīng)賬號(hào)查看Membership獲取
method:app-store、enterprise薛闪、ad-hoc辛馆、development
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>enterprise</string>
<key>teamID</key>
<string>xxx</string>
<key>compileBitcode</key>
<false/>
</dict>
</plist>
相對(duì)build_deployto_fir.sh主要做了以下變動(dòng):
1)xrun替換為xcodebuild -exportArchive
2)從遠(yuǎn)程clone代碼,防止本地代碼不是最新代碼
3)優(yōu)化一些其他邏輯
參考鏈接:
1)http://www.reibang.com/p/bccbb37f21f9
2)https://github.com/heyuan110/BashShell