iOS自动构建有fastlane等工具,实际使用过程没问题的没必要换。
我是碰到了一下fastlane无法解决的问题,而且不喜欢用框架,所以自己写了xcode命令行构建脚本,下边是脚本代码,看下代码注释稍微修改下放Jenkins中即可,有问题可以留言,欢迎交流。
#解锁keychain
security unlock-keychain -p"xxxxxx" ${HOME}/Library/Keychains/login.keychain-db
#改构建号
agvtool new-version -all ${BUILD_NUMBER}
#改版本号
agvtool new-marketing-version x.x.x
#替换证书(debug/release证书不一致时需要,一致时不需要替换)
pbpath="./XXX.xcodeproj/project.pbxproj"
sed -i '' s/com.crgt.XXX.dev/com.crgt.XXX/g ${pbpath}
sed -i '' s/Apple\ Development/iPhone\ Distribution/g ${pbpath}
sed -i '' s/iPhone\ Developer/iPhone\ Distribution/g ${pbpath}
sed -i '' s/XXXNotificationDev/XXXNotificationDis/g ${pbpath}
sed -i '' s/XXXTodayDev/XXXTodayDis/g ${pbpath}
sed -i '' s/XXXDev/XXXDis/g ${pbpath}
# xcode命令行构建并上传AppStore
time=$(date +%Y%m%d%H_%M_%S)
export_path="./export/XXApp${time}"
xcodebuild archive -archivePath ${export_path}/XXX.xcarchive -workspace XXX.xcworkspace -scheme XXX -configuration Release -sdk iphoneos13.7(构建依赖的SDK版本,需要自己改)
# dsym文件保存路径
DWARF_DSYM_FOLDER_PATH=$export_path/${BUILD_NUMBER}XXX.app.dSYM
# ExportOptions文件,手动构建一次,导出的ipa包同级目录就有,拷贝一下
#编译
xcodebuild -exportArchive -archivePath ${export_path}/XXApp.xcarchive -exportPath ${export_path}/ipa -exportOptionsPlist ../ExportOptions/ExportOptionsDistribution.plist
#校验
xcrun altool --validate-app -t ios -f ${export_path}/ipa/XXApp.ipa -u xxx@xxx.com -p @keychain:MY_SECRET --output-format xml
#上传App Store
xcrun altool --upload-app -t ios -f ${export_path}/ipa/XXApp.ipa -u xxx@xxx.com -p @keychain:MY_SECRET --output-format xml
# 压缩dsym,上传bugly等平台需要zip
cd $export_path
zip -r ${BUILD_NUMBER}XXApp.app.dSYM.zip ${BUILD_NUMBER}XXApp.app.dSYM