原文链接:http://www.jianshu.com/p/5abbe0d61cef
参考链接:http://blog.csdn.net/potato512/article/details/52176073
开头
前面几片记录了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_马建成(简书作者)
原文链接:http://www.jianshu.com/p/5abbe0d61cef
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
原文链接:http://www.jianshu.com/p/5abbe0d61cef
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。