Jenkins 打包 iOS
2016-12-28 本文已影响1347人
小弱鸡
公司希望开发和发布时候打包增加工作效率,减少人工的介入。希望我们iOS 端寻找一个工具来实现可持续化集成。经过对比我们选择了jenkins 来实现我们的需求。经过历时一周一百五十次左右的失败终于构建打包成功了。
** 第一步 安装 JRE环境 **
Jenkins 运行依赖于java环境 ,没有安装的请去官网自行下载安装
** 第二步 安装 Jenkins **
请依然去Jenkins官网下载安装。

Mac端选择Mac OSX 下载。
接下来盗几张图:






修改不可访问打开文件的权限获取里面的密码将其填充一下,如下图

点击左侧一个模块进入下载页面,时间可能会很久,耐心等待



自定义设置用户名及密码,点击保存并完成按钮,进入下图页面。

第三步 添加项目及相关参数配置
下面来添加项目

安装插件:我安装的主要有两个管理证书的 ****Keychains and Provisioning Profiles Management**** 和 从svn拉代码的****Subversion Plug-in****。自己需要什么的样见仁见智。




****添加文件 (避免找不到证书配置文件的情况出现)****
1、将login.keychain文件粘贴到
/Users/Shared/Jenkins/Library/Keychains
(获取login.keychain文件~/Library/Keychains/
)2、配置文件粘贴到jenkins 的
/Users/Shared/Jenkins/Library/MobileDevice/Provisioning Profiles
文件下。****没有文件夹就去创建一个新的名为其的文件夹****

个人觉得下面这两步大概可以省略,但不知道会不会有不良后果。


****配置工程****

****配置svn链接****


****添加脚本****:由于使用xcode插件三天左右没有打包成功,于是便放弃了,使用脚本打包


****脚本如下:****
# 工程名
APP_NAME="你的工程名"
# 证书
CODE_SIGN_DISTRIBUTION="证书名称"
# info.plist路径
project_infoplist_path="./${APP_NAME}/Info.plist"
#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}")
#取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")
DATE="$(date +%Y%m%d)"
IPANAME="${APP_NAME}_V${bundleShortVersion}_${DATE}.ipa"
#要上传的ipa文件路径
IPA_PATH="$HOME/${IPANAME}"
echo ${IPA_PATH}
echo "${IPA_PATH}">> text.txt
#获取权限
security unlock-keychain -p "打包机器登录密码" $HOME/Library/Keychains/login.keychain
# //下面2行是没有Cocopods的用法
# echo "=================clean================="
# xcodebuild -target "${APP_NAME}" -configuration 'Release' clean
# echo "+++++++++++++++++build+++++++++++++++++"
# xcodebuild -target "${APP_NAME}" -sdk iphoneos -configuration 'Release' CODE_SIGN_IDENTITY="${CODE_SIGN_DISTRIBUTION}" SYMROOT='$(PWD)'
#//下面2行是集成有Cocopods的用法
echo "=================clean================="
xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_NAME}" -configuration 'Debug' clean
echo "+++++++++++++++++build+++++++++++++++++"
xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_NAME}" -sdk iphoneos -configuration 'Debug' CODE_SIGN_IDENTITY="${CODE_SIGN_DISTRIBUTION}" SYMROOT='$(PWD)'
xcrun -sdk iphoneos PackageApplication "./Debug-iphoneos/${APP_NAME}.app" -o ~/"${IPANAME}"
****注:非pods版本的尚未自己测试,不能保证其准确性,如果有问题请留言指出****


点击构建坐等输出。(出错是难免的,摸石头过河,遇到问题解决问题)
秀一下成果。

不足之处:脚本最后一句命令是过时的,由于本人水平有限,不懂shell语言,没法实现修改,也无法是打包的ipa文件打包到指定路径。后期如果有可能本人会慢慢的完善的。
参考资料:
一步一步构建iOS持续集成:Jenkins+GitLab+蒲公英+FTP
手把手教你利用Jenkins持续集成iOS项目
Jenkins持续集成iOS项目