xcodebuild編譯ipa

#!/bin/sh

#  autoBuild.sh
#  CTest
#
#  Created by Ethan on 14-11-3.
#  Copyright (c) 2014年 Ethan. All rights reserved.

###############################################
#使用方法
#./build.sh arg1 arg2 arg3 arg4
#arg1 項目的路徑,例如:/Volumes/work/buildCommand/test/CTest
#arg2 爲項目編譯ID
#arg3 爲編譯完成回調地址
#arg4 公司項目特殊用法
#服務器須要修改源
###############################################

###############################################
#回調函數
function fCallBack()
{
    echo $1 #1/-1
    echo $2 #buildID
    echo $3 #http://www.baidu.com
#echo ${logPath}
# echo ${ipaPath}

    url="${3}?status=${1}&buildId=${2}&logger=${logPath}&package=${ipaPath}"
#echo $url
    curl $url
}


###############################################
#參數檢查
if [ -z "$1" ]; then
echo "error:項目路徑爲空"
exit 1
fi

if [ -z "$2" ]; then
echo "error:項目編譯ID爲空"
exit 1
fi

if [ -z "$3" ]; then
echo "error:回調地址爲空"
exit 1
fi

if [ -z "$4" ]; then
echo "error:證書編號爲空"
exit 1
fi


#日誌地址
logPath="${1}/log.txt"
#ipa地址
ipaPath="${1}/${2}.ipa"
##############################################
#證書檢查
PROFILE_FILE="/Volumes/${4}.mobileprovision"
echo $PROFILE_FILE
UUID=`/usr/libexec/PlistBuddy -c 'Print :UUID' /dev/stdin <<< $(security cms -D -i ${PROFILE_FILE} )`
if [ -z "$UUID" ]; then
echo "error:找不到證書"
exit 1
fi
echo $UUID
cp ${PROFILE_FILE} "$HOME/Library/MobileDevice/Provisioning Profiles/${UUID}.mobileprovision"

###############################################
#清理項目
cd $1
xcodebuild clean


###############################################
#編譯並將日誌寫到文件 正式使用須要修改PROVISIONING_PROFILE
xcodebuild  -sdk iphoneos PROVISIONING_PROFILE=${UUID} > ${logPath}
#判斷是否編譯成功
if [[ $? -eq 0 ]];  then
    echo "build success"
else
    echo "build error"
    fCallBack "-1" $2 $3
    exit 2
fi


###############################################
#生成ipa

xcrun -sdk iphoneos PackageApplication -v ./build/Release-iphoneos/*.app -o ${ipaPath}
if [[ $? -eq 0 ]];  then
rm -rf build
echo "create ipa success"
fCallBack "1" $2 $3
exit 0
else
echo "create ipa error"
fCallBack "-1" $2 $3
exit 2
fi
相關文章
相關標籤/搜索