首先,建议先查看官方帮助文档xcodebuild -help
打包:
xcodebuild -workspace <workspacename> -scheme <schemeName> [-destination <destinationspecifier>]... [-configuration <configurationname>] [-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]] [-showBuildSettings] [<buildsetting>=<value>]... [<buildaction>]...
导出包:
xcodebuild -exportArchive -archivePath <xcarchivepath> -exportPath <destinationpath> -exportOptionsPlist <plistpath>
结合实际项目命令如下:
#打包
xcodebuild archive -workspace Cicada.xcworkspace -scheme "Cicada" -configuration Release -archivePath ${ARCHIVEPATH}/Cicada -quiet
#导出IPA包
xcodebuild -exportArchive -archivePath "${ARCHIVEPATH}/Cicada.xcarchive" -exportPath ${EXPORTPATH} PROVISIONING_PROFILE_SPECIFIER AppStore -exportOptionsPlist ${ExportOptionsPlist} -quiet
解释:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>app-store</string>
<key>uploadBitcode</key>
<false/>
<key>uploadSymbols</key>
<false/>
</dict>
</plist>
altool 上传基础命令
#验证APP
${altoolpath} --validate-app -f ${filepath} -u username [-p password] [--output-format xml]
#上传APP
${altoolpath} --upload-app -f ${filepath} -u username [-p password] [--output-format xml]
命令解释
密码获取步骤:
#设置基础路径和信息
ARCHIVEPATH="${WORKSPACE}/iOSArchivePackage"
EXPORTPATH="${WORKSPACE}/outputs"
ExportOptionsPlist="/Users/Shared/Jenkins/workspace/taoism/builds/app-store.plist"
ALTOOLPATH=/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool
IPAPATH="${WORKSPACE}/outputs/Cicada.ipa"
APPID="sample@app.com"
APPPASSWORD="samplepassword"
#获取钥匙串和打包电脑密码
security unlock-keychain -p "password" $keychainPath
#clean工程目录
xcodebuild clean -configuration "Release" -alltargets
#导出archive文件
xcodebuild archive -workspace Cicada.xcworkspace -scheme "Cicada" -configuration Release -archivePath ${ARCHIVEPATH}/Cicada -quiet
#导出IPA包
xcodebuild -exportArchive -archivePath "${ARCHIVEPATH}/Cicada.xcarchive" -exportPath ${EXPORTPATH} PROVISIONING_PROFILE_SPECIFIER profilename -exportOptionsPlist ${ExportOptionsPlist} -quiet
#验证信息
"${ALTOOLPATH}" --validate-app -f "${IPAPATH}" -u "${APPID}" -p "${APPPASSWORD}" --output-format xml
#上传iTunesConnect
"${ALTOOLPATH}" --upload-app -f "${IPAPATH}" -u "${APPID}" -p "${APPPASSWORD}" --output-format xml