3

Jenkins for iOS 搭建日记

 2 years ago
source link: https://www.isaced.com/post-279.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Jenkins for iOS 搭建日记

一直以来被 iOS 项目打包困惑,速度慢、操作复杂,深恶痛绝!于是开始寻求网络上的持续集成服务,前两天尝试了下 buddybuild、bitrise,都不太如意(可能是姿势不太对),正好公司有台空着的 Mac mini,刚好可以拿来试试搭个 Jenkins 服务器做持续集成,网络上有很多 Jenkins 安装教程,这里就不重复了,主要记录一下我在使用过程中遇到的问题和解决方法,希望未来某一天能帮到同样被困惑的人儿。

再说点闲言碎语,关于 iOS 的打包的进阶历程,最早没接触这些东西的时候是每次手动在 Xcode 上 Archive -> Organizer -> Export,必须守在电脑前,中间操作步骤也很多,特别是在 Organizer 里面签名,很容易就出现证书或者 PP(Provisioning Profiles) 文件不正确之类的问题;后来知道了 fastlane,写好脚本用 gym 一键打包,感觉生活品质上了一个量级;后来了解到持续集成,比如 Jenkins,项目丢服务器上去,推送代码自动打包、分发、推送提醒,体验更上一层楼。

遇到的问题

Unable to unlock the keychain.

可能遇到错误 User interaction is not allowed ,那么你可能需要在 script 里先执行一下这一行命令来给 keychain 解锁:

security unlock-keychain -p "YourPassword" ~/Library/Keychains/login.keychain

然后可以用这行来验证是否解锁成功:

security show-keychain-info ${HOME}/Library/Keychains/login.keychain

因为在 Jenkins script 里没有输入交互,如果不在命令中跟上 -p 密码的话是会失败的。

Cocoapods 依赖更新失败

通常需要在编译项目前执行 pod install 来安装依赖,如果你的 Podfile 里引用了私有 pod,如果通过 https 访问的话,那么一般在终端中会自动提示输入对应 git 访问账号密码,可是在 jenkins 里没有输入交互,所以这时候之后在 jenkins 和 git 里配置正确的私钥-公钥才能正确访问,并且 Podfile 里的地址改为 git 打头才行。

如果还是想用 https 访问的话另外有个取巧的简单,就是 ssh 进去 jenkins 用户,手动 pod install 一遍,手动输入账号信息,系统则会记录下来,下次就不会再提示,从而在 jenkins 里也能正常。

一些小技巧

编译成功 iMessage 通知

一般编译成功后大家可能会设定发送邮件通知,其实也可以直接通过 AppleScript 发送一条 iMessage 信息,还挺好玩的。

在构建步骤的 script 里可能会是这样:

osascript -e 'tell application "Messages" to send "'"${scheme}(${BUILD_DISPLAY_NAME}) build complete."'" to buddy "[email protected]" of (service 1 whose service type is iMessage)'

这个地方被困惑的是在 Shell 里调用 osascript -e ,为了引入 jenkins 的 environment variables ,写的时候单双引号已经快要把我整残废了。 最终就可以在你的 iPhone 上收到 iMessage 提醒,效果如下图:

iMessage

编译成功 fir 上传

可以在编译成功后提交 .ipa 到 fir,通过 fir.im-cli 上传,或者安装 fir-jenkins 插件

fir publish ${ipa_path} -T YOUR_TOKEN

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK