Jenkins集成iOS自动化打包(GitLab + xcodebuild + xcrun + ftp)

参考链接iOS持续集成:Jenkins+GitLab+蒲公英  讲了几种自动化打包的配置方式、很详细!


下面主要是针对使用xcodebuild + xcrun编写脚本配置的方式做一个踩坑记录,我就是用的这个。

一、在全局配置中选择Keychains and Provisioning Profiles Management




二、进入到创建的项目下

(1)源码管理


(2)构建触发器+构建环境


(3)构建


(4)构建后操作(存到ftp服务)



三、xcodebuild + xcrun 脚本

# 工程名/Target/Schema

APP_NAME="test"

# 项目绝对路径

PROJECT_PWD_PATH="$PWD/ios/test.xcodeproj"

# build 路径

BUILD_PATH="$PWD/ios/build/Release-iphoneos"

# configuration

CONFIGURATION_TYPE="Release"

# info.plist路径

INFO_PLIST_PATH="$PWD/ios/test/Info.plist"

# 签名

CODE_SIGN_NAME="iPhone Distribution: xxxxxx Net Co.,Ltd"

# 描述文件

MOBILE_PROVISION="883xxxxxx0-xxxxx-xxxxx-f4d.mobileprovision"

# 取版本号

bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${INFO_PLIST_PATH}")

# 取build值

bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${INFO_PLIST_PATH}")

# 日期

DATE="$(date +%Y%m%d)"

# 生成.ipa名称

IPANAME="${APP_NAME}_V${bundleShortVersion}_${DATE}.ipa"

# .ipa路径

IPA_PATH="$PWD/ios/build/${IPANAME}"



# remove Build_Directory

rm -rf "$PWD/ios/build"

# clean

xcodebuild clean -project ${PROJECT_PWD_PATH} -configuration ${CONFIGURATION_TYPE} -target ${APP_NAME} -quiet || exit 

# build

xcodebuild -project ${PROJECT_PWD_PATH} -configuration ${CONFIGURATION_TYPE} -scheme ${APP_NAME} -sdk iphoneos11.0 -arch arm64 CONFIGURATION_BUILD_DIR=${BUILD_PATH} -quiet || exit

# export

xcrun -sdk iphoneos11.0 PackageApplication -v "${BUILD_PATH}/${APP_NAME}.app" -o ${IPA_PATH} CODE_SIGN_IDENTITY ${CODE_SIGN_NAME}  --embed ${MOBILE_PROVISION} || exit


# open ${IPA_PATH}

# export_plist
# EXPORT_PLIST="~/Desktop/ExportOptions_temp.plist"
# .xcarchive路径
#XCARCHIVE_PATH="$PWD/ios/build/CaibaClient.xcarchive"
#xcodebuild archive -project ${PROJECT_PWD_PATH} -scheme ${APP_NAME} -configuration Release -archivePath "${XCARCHIVE_PATH}" -quiet || exit
#xcodebuild -exportArchive -archivePath "${XCARCHIVE_PATH}" -exportPath ${IPA_PATH} -exportOptionsPlist ${EXPORT_PLIST} -quiet || exit

修改上面的脚本就可以使用,主要是修改相关的路径和工程名。

其中:

1. target和schema可以在项目路径下执行命令xcodebuild -list查看

2.在项目路径下执行命令xcodebuild -showsdks查看支持的sdk参数

3.此处是针对.xcodeproj项目,如果是使用的cocoapods集成的项目,需执行pod install,并且工程名不再是.xcodeproj而是.xcworkspace,具体可参考iOS持续集成:Jenkins+GitLab+蒲公英

4.上面的脚本可以改成后缀名为.sh的文件xcodebuild.sh置于*.xcodeproj同级目录,在该目录下使用命令./xcodebuild.sh即可运行脚本自动打包,如无权限执行命令chmod +x xcodebuild.sh

5.在上面export命令中使用了PackageApplication ,它是在旧版的xcode中存在,用来将.app文件转成.ipa,但是在Xcode 9中已经废弃了这个。

一种解决方式是使用新的脚本命令-exportArchive导出.ipa

另一种方式就是拷贝这个文件到新的Xcode目录下。 文件下载链接-----PackageApplication Download 下载后放到指定目录下并执行命令即可

# 放到指定目录
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/

# 终端执行下面两条命令
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

chmod +x /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication

6.如果使用Xcode工具进行构建,需要的team name 和 team id 可登陆 Developer 网站查看

       

猜你喜欢

转载自blog.csdn.net/NB_Token/article/details/80018747