Xcode11打包shell

很久没更新了。来更新一波。shell打包上传到AppStore,用于版本发布或者TestFlight

scheme 是外部传入的参数。
帐号是苹果的帐号,密码要去生成一个app专用密码,不是登陆用的密码。
通过https://itunes.apple.com/lookup接口获取当前商店的版本,然后加1。
需要安装jq解析json,build id直接用的时间戳
第一次运行可能会报xcode-select的问题 一般这样就可以了

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

下面是代码

#!/bin/bash -l
set -e
cd $(dirname $0)
echo | pwd

#外部传入的scheme
SHCEME=$1
ACCOUNT=xxxxxxxxx
PASSWORD=xxxx-xxxx-xxxx-xxxx

#更新pod
pod install

#workspace
WORKSPACE=xxxx.xcworkspace
TIME_STAMP=`date "+%Y%m%d%H%M%S"`
ArchivePath=JenkinsPackage/${SHCEME}_${TIME_STAMP}.xcarchive
PackagePath=JenkinsPackage/${SHCEME}_${TIME_STAMP}
IPAPATH=$(pwd)/${PackagePath}/${SHCEME}.ipa
EXPORT_OPTIONS=ExportOptions_Release.plist
 
#获取版本号 需要安装jq解析json xxxxx自己的appid
VERSION=$(curl 'https://itunes.apple.com/lookup?id=xxxxxx' | jq '.results[0].version')
VERSION=`echo $VERSION |sed 's/\"//g' | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'`

echo $SHCEME
echo $VERSION
echo $TIME_STAMP
echo $IPAPATH
#修改版本号
agvtool new-marketing-version ${VERSION}
agvtool new-version -all ${TIME_STAMP}

#archive
xcodebuild archive -workspace ${WORKSPACE} -scheme ${SHCEME} -archivePath ${ArchivePath} -allowProvisioningUpdates
#export
xcodebuild -exportArchive -archivePath ${ArchivePath} -exportPath ${PackagePath} -exportOptionsPlist ${EXPORT_OPTIONS} -allowProvisioningUpdates
#发布至App Store
xcrun altool --validate-app -f ${IPAPATH} -u ${ACCOUNT} -p ${PASSWORD} -t ios --output-format normal
xcrun altool --upload-app -f ${IPAPATH} -u ${ACCOUNT} -p ${PASSWORD} -t ios --output-format normal

export的参数 根据自己需要配置
ExportOptions_Release.plist





    compileBitcode
    
    method
    app-store
    teamID
    xxxxxxxxx


你可能感兴趣的:(Xcode11打包shell)