iOS 自动化构建 xcodebuild

xcidebuild

apple 官网 xcodebuild 文档

使用 shell 实现 clean、build、archive、export 等功能
自动化构建主要还是使用 clean、archive、export

  • 先用 xcode 手动打个包,比如 ad_hot 的包并导出,可以得到 ipa 包,以及「ExportOptions.plist」以供后续使用(打 appstore 包,也会有一个)

project 自动签名

#!/bin/bash

# jenkins 下,默认是项目文件夹,也是默认参数(此处用以本机测试)
WORKSPACE=~/Desktop/test

# 项目路径
PROJECT_NAME="test"
TARGET_NAME="test"
PROJECT_PATH=${WORKSPACE}/$PROJECT_NAME.xcodeproj

# 输出配置
# EXPORT_OPTIONS_PLIST 的 plist 就是打包来的 ExportOptions.plist,修改了名字
EXPORT_OPTIONS_PLIST=${WORKSPACE}/export/export_ad_hot.plist
RES_DIR=~/Desktop/${TARGET_NAME}pack
RES_ARCHIVE_PATH=${RES_DIR}/ach.xcarchive
RES_IPA_DIR=${RES_DIR}/ipa
RES_IPA_PATH=${RES_IPA_DIR}/${TARGET_NAME}.ipa


# clean
xcodebuild OTHER_CFLAGS="-fembed-bitcode" clean -project $PROJECT_PATH -scheme $TARGET_NAME

# archive
xcodebuild OTHER_CFLAGS="-fembed-bitcode" archive -archivePath $RES_ARCHIVE_PATH  -project $PROJECT_PATH -scheme $TARGET_NAME

# export
xcodebuild OTHER_CFLAGS="-fembed-bitcode" -exportArchive -archivePath $RES_ARCHIVE_PATH -exportPath $RES_IPA_DIR -exportOptionsPlist $EXPORT_OPTIONS_PLIST

echo "打包成功:${RES_IPA_PATH}"

workspace 手动签名

#!/bin/bash

# jenkins 下,默认是项目文件夹,也是默认参数(此处用以本机测试)
WORKSPACE=~/Desktop/qiakr

export LC_ALL=zh_CN.GB2312;export LANG=zh_CN.GB2312

# 项目路径
WORKSPACE_NAME="xxx"
TARGET_NAME="xxx"
WORKSPACE_PATH=${WORKSPACE}/RealCloud/xxxx/${WORKSPACE_NAME}.xcworkspace

# 项目配置
BUILD_CONFIG="Release"
PRODUCT_BUNDLE_IDENTIFIER="com.xxx.xxxx.app"
CODE_SIGN_IDENTITY="iPhone Distribution: Hangzhou xxxx Technology Co, Ltd. (xxxx)"
PROVISIONING_PROFILE="xxxx-e40b-487b-8a2c-xxxxx"
ENABLE_BITCODE="YES"

# 输出配置
EXPORT_OPTIONS_PLIST=~/Desktop/ad_hot_qa.plist
RES_DIR=~/Desktop/${TARGET_NAME}-pack
RES_ARCHIVE_PATH=${RES_DIR}/ach.xcarchive
RES_IPA_DIR=${RES_DIR}/ipa
RES_IPA_PATH=${RES_IPA_DIR}/${TARGET_NAME}.ipa

# clean
xcodebuild OTHER_CFLAGS="-fembed-bitcode" clean -workspace $WORKSPACE_PATH -scheme $TARGET_NAME

# archive
xcodebuild OTHER_CFLAGS="-fembed-bitcode" archive -archivePath $RES_ARCHIVE_PATH -workspace $WORKSPACE_PATH -scheme $TARGET_NAME -configuration $BUILD_CONFIG CODE_SIGN_IDENTITY="${CODE_SIGN_IDENTITY}" PROVISIONING_PROFILE=${PROVISIONING_PROFILE} PRODUCT_BUNDLE_IDENTIFIER=${PRODUCT_BUNDLE_IDENTIFIER} ENABLE_BITCODE=${ENABLE_BITCODE}

# export
xcodebuild OTHER_CFLAGS="-fembed-bitcode" -exportArchive -archivePath $RES_ARCHIVE_PATH -exportPath $RES_IPA_DIR -exportOptionsPlist $EXPORT_OPTIONS_PLIST

echo "打包成功:${RES_IPA_PATH}"

相关说明

project 和 workspace 都是可以手动和自动的,手动的话需要配置证书和配置文件
pod 之后的就对应使用 workspace,不使用 project

附录1:上传蒲公英

蒲公英文档

很简单,注意 path 即可

path=$RES_IPA_PATH
API_KEY=742cd3ecae1032adc45a6ce59d759c7f
MSG="QA 测试包-正式环境"

a=$(curl -F "file=@$path" -F "_api_key=$API_KEY" -F "buildUpdateDescription=${MSG}" https://www.pgyer.com/apiv2/app/upload)

附录2:jenkins 补充

# 构建后操作:补充个二维码下载安装链接
# set build description
# "appQRCodeURL":"(.*)"
#  二维码

附录3:sh 运行权限

添加本地 sh 文件运行权限
chmod u+x ~/Desktop/test.sh

你可能感兴趣的:(iOS 自动化构建 xcodebuild)