shell打包到fir 蒲公英

littleplayer發表於2017-12-26

####開頭 前面幾片記錄了jenkins的使用,配置一個jenkins環境,我們需要一個比較閒得筆記本做這份工作,不可能自己的本一直開著這個服務,動不動CPU風扇狂轉,其他效能下降,反而會影響我們工作,怎麼辦了,寫個shell指令碼幫我們完成工程打包、上傳。 ####原理 xcode在jenkins中編譯、shell編譯還是xcode自身編譯都是需要xcode自己的IDE環境決定的,具體來說就是

xcodebuild & xcrun這倆傢伙來完成
複製程式碼

廢話不多說,直接上指令碼,需要的自己改一下即可。

####project打包上傳

#!/usr/bin/bash

#next test
#1.證書
#2.打包狀態每部判斷

#設定Xcode的Build Settings->Code Signing Resource Rules Path的值為:$(SDKROOT)/ResourceRules.plist 


 #xcodeproj檔案的絕對路徑
PROJECT="/Users/mac/Desktop/pro/git/MCPayDemo/MCPayDemo.xcodeproj"

SCHEME="MCPayDemo"

#iPhone Distribution:
IDENTITY="iPhone Developer: ma jiancheng (xxxxx)"  

#Distribution Provision File Path
PROVISIONING_PROFILE="/Users/mac/Library/MobileDevice/Provisioning\ Profiles/ead3e7e7-a2e8-45c2-98fa-008f3712xxxx.mobileprovision"

#輸出ipa檔案的路徑, 最好是絕對路徑
OUTDIR="/Users/mac/Desktop/pro/git/MCPayDemo/output"

PRODUCTDIR=${OUTDIR}
#FIR 祕鑰
FIRTOKEN="5558b26ae383df7390b880xxxxxxx"
#蒲公英aipKey
PAPIKEY="c1ad57c15a5bb0c770c51639xxxxxxx"
#蒲公英uKey
PUKEY="d5eb8f86040b9ae6108ed4c58xxxxxxx"
 
if [ ! -f $PROVISIONING_PROFILE ]; then
    echo "Please download the provision file for "${PROVISIONING_PROFILE}
    exit 4;
fi
echo "~~~~~~~~~~~~~~~~清理工程~~~~~~~~~~~~~~~~編譯工程~~~~~~~"
echo "${OUTDIR}${SCHEME}.ipa"
echo "xcrun -sdk iphoneos PackageApplication -v ${PRODUCTDIR}/${SCHEME}.app -o ${OUTDIR}/${SCHEME}.ipa --sign ${IDENTITY} --embed ${PROVISIONING_PROFILE}"
xcodebuild -project "${PROJECT}" -scheme "${SCHEME}" -configuration  Release clean build CODE_SIGN_IDENTITY="${IDENTITY}" -sdk iphoneos CONFIGURATION_BUILD_DIR=${OUTDIR} 
#打包成 .ipa
echo "~~~~~~~~~~~${SCHEME}.ipa}~~~scuess"
echo "xcrun -sdk iphoneos PackageApplication -v ${PRODUCTDIR}/${SCHEME}.app -o ${OUTDIR}/${SCHEME}.ipa --sign \"${IDENTITY}\" --embed ${PROVISIONING_PROFILE}"
xcrun -sdk iphoneos PackageApplication -v "${PRODUCTDIR}/${SCHEME}.app" -o "${OUTDIR}/${SCHEME}.ipa"
# --sign "\"${IDENTITY}\"" --embed "${PROVISIONING_PROFILE}"


#上傳到測試平臺 -> fir.im
fir p "${OUTDIR}/${SCHEME}.ipa" -T "${FIRTOKEN}"

echo "-------------------->fir.im------->蒲公英---------"
echo "curl -F file=@${OUTDIR}/${SCHEME}.ipa -F uKey=${PUKEY} -F _api_key=${PAPIKEY} http://www.pgyer.com/apiv1/app/upload"
curl -F "file=@${OUTDIR}/${SCHEME}.ipa" -F "uKey=${PUKEY}" -F "_api_key=${PAPIKEY}" "http://www.pgyer.com/apiv1/app/upload"
echo "\n\n"


複製程式碼

####workspace打包上傳

/#!/usr/bin/bash
#############################################
/# batch rename                         	    #
/# Input  :    $1 SCHEME  					#
/#             eg:需要編譯的scheme    			#
/# Input  :    $2 PROVISION PREFIX       	#
/#             eg: mobileprovision檔案的名稱	#
#############################################

#next test
#1.證書
#2.打包狀態每部判斷

#設定Xcode的Build Settings->Code Signing Resource Rules Path的值為:$(SDKROOT)/ResourceRules.plist 


 #xcodeproj檔案的絕對路徑[修改]
WORKSPACE_PATH="/Users/mac/Desktop/car/Runnor.CarService.IosApp/"
WORKSPACE_NAME="MCCarServiceiPhone"
SCHEME="MCCarServiceiPhone"

#生成的APP名稱,根據xcode專案 plist來定
APPNAME="MCCarServiceiPhone"

#iPhone Distribution: FOO.
IDENTITY="\"iPhone Developer: ma jiancheng (xxxxxxxxx)\""  

#Distribution Provision File Path
PROVISIONING_PROFILE="/Users/mac/Library/MobileDevice/Provisioning\ Profiles/ead3e7e7-a2e8-45c2-98fa-008f3712382d.mobileprovision"

#輸出ipa檔案的路徑, 最好是絕對路徑
OUTDIR="${WORKSPACE_PATH}/output"

#FIR 祕鑰
FIRTOKEN="5558b26ae383df7390b880bexxxxxxx"
#蒲公英aipKey
PAPIKEY="c1ad57c15a5bb0c770c51639xxxxxxx"
#蒲公英uKey
PUKEY="d5eb8f86040b9ae6108ed4c5xxxxxxxx"


if [ ! -f $PROVISIONING_PROFILE ]; then
    echo "Please download the provision file for " ${PROVISIONING_PROFILE}
    exit 4;
fi
echo "~~~~~~~~~~~~~~~~清理工程~~~~~~~~~~~~~~~~編譯工程~~~~~~~"
echo "${OUTDIR}${APPNAME}.ipa"
echo "xcodebuild -workspace ${WORKSPACE_NAME}.xcworkspace -scheme ${SCHEME} -configuration  Release clean build CODE_SIGN_IDENTITY=${IDENTITY} -sdk iphoneos CONFIGURATION_BUILD_DIR=${OUTDIR}"
xcodebuild -workspace "${WORKSPACE_PATH}/${WORKSPACE_NAME}.xcworkspace" -scheme "${SCHEME}" -configuration  Release clean build CODE_SIGN_IDENTITY="${IDENTITY}" -sdk iphoneos CONFIGURATION_BUILD_DIR=${OUTDIR} 
#打包成 .ipa
echo "~~~~~~~~~~~${APPNAME}.ipa}~~~scuess"
echo "xcrun -sdk iphoneos PackageApplication -v ${OUTDIR}/${APPNAME}.app -o ${OUTDIR}/${APPNAME}.ipa --sign ${IDENTITY} --embed ${PROVISIONING_PROFILE}"
xcrun -sdk iphoneos PackageApplication -v "${OUTDIR}/${APPNAME}.app" -o "${OUTDIR}/${APPNAME}.ipa"
# --sign "${IDENTITY}" --embed "${PROVISIONING_PROFILE}"


#上傳到測試平臺 -> fir.im
echo "-------------------->fir.im------->蒲公英---------"
#fir p "${OUTDIR}/${SCHEME}.ipa" -T "${FIRTOKEN}"
# ->  蒲公英

echo "curl -F file=@${OUTDIR}/${APPNAME}.ipa -F uKey=${PUKEY} -F _api_key=${PAPIKEY} http://www.pgyer.com/apiv1/app/upload"
curl -F "file=@${OUTDIR}/${APPNAME}.ipa" -F "uKey=${PUKEY}" -F "_api_key=${PAPIKEY}" "http://www.pgyer.com/apiv1/app/upload"
echo "\n\n"

#--------------------end--------------

複製程式碼

####結語 這個shell語句寫的比較簡單,等閒暇會在本文優化。本文是jenkins的一個衍生,後續會在jenkins上探索一些持續構建的工作。

@lp_馬建成

相關文章