iOS continuous build environment

content:

1. Description

2. Environmental information

3. Construction steps

       1. Configure the apple certificate

              1) Create Certificate Signing Request

              2) Create a certificate

              3) Import the certificate

              4) Download profile

       2. Install Cocoapods

              1) Replace the RubyGems source

              2) Install cocoapods

       3、Jenkins

              1) Install Jenkins

              2) Install the Jenkins plugin

              3) Environment variables

              4) Configure the certificate

              5) Task configuration

                     a. Certificate selection

                     b. Dependency package update

                     c. Xcode compilation

                     d. Xcode packaging

Fourth, encounter problems

5. References

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

1. Description

The construction of this environment is mainly to realize the automatic packaging of iOS apps without manual participation. Based on this environment, SonarQube code quality inspection, unit testing, etc. can be integrated.

Output: ipa

 

This article focuses on the configuration instructions related to iOS, and does not introduce the basic environment.

2. Environmental information

System: Mac OS X 10.10.5

Xcode:7.2

Ruby:2.2.1

RubyGems: 2.4.8

JDK:1.7.0_79

Jenkins:1.636

Cocoapods:0.37.2

 

3. Construction steps

1. Configure the apple certificate

1) Create Certificate Signing Request

Create a Certificate Signing Request via Keychain Access in Mac:




 Save the .certSigningRequest file.

2) Create a certificate

Log in to the Apple developer website and create a certificate (you need to upload the .certSigningRequest file generated in the previous step):



 

3) Import the certificate

Download the certificate generated in the previous step to the Mac, dual-machine certificate, and the "Keychain Access" tool will be launched when the certificate is opened:



 

4) Download profile

Open Xcode-->Preferences..., log in to the developer account, select the corresponding Team, View Details...:



 点击相应签名后面的“Reset”按钮,将对应的Profile下载到本地(下载完只会Reset按钮将消失,如下图):


2、安装Cocoapods

1)更换RubyGems源

 

$ gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/

    查看是否更换成功:

 

 

$ gem sources -l

 

2)安装cocoapods

由于项目需求,本次搭建cocoapods使用0.37.2版本:

$ sudo gem install cocoapods -v 0.37.2
$ pod setup

 setup过程会非常缓慢,可通过以下命令查看是否有进度(文件大小是否增长):

$ cd ~/.cocoapods/repos
$ du -sh *

 

3、Jenkins

1)安装Jenkins

使用 homebrew 安装 Jenkins:

$ brew install jenkins

 

然后链接 launchd 配置文件:

$ ln -sfv /usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents

 修改完后,在终端执行:

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist

 即可启动 Jenkins。

接着用浏览器访问 http://localhost:8080(默认配置),就可以看到 Jenkins 的 web 界面了。

 

2)安装Jenkins插件

  • Git plugin(Git集成,拉取代码)
  • Xcode integation(Xcode集成,编译打包)
  • Keychains and Provisioning Profiles Management(证书集成)

3)环境变量

系统设置——>全局属性,勾选Environment variables,新增键值对,配置ruby路径:



 

4)配置证书

系统管理——>Keychains and Provisioning Profiles Management,分别上传~/Library/Keychains/login.keychain,~/Library/MobileDevice/Provisioning Profiles/前面下载到本地的对应profile文件,

并填写证书名称(在钥匙串访问中右击证书“显示简介”,把常用名称复制下来):



 

5)任务配置

新建一个自由风格的Jenkins任务,配置Git等项。继而进行以下配置:

a、证书选择

选中Keychain and Code Signing Identities,选择相应的keychain(其它项保存后会自动更新),如下图;

选中Mobile Provisioning Profiles,选择想过要的Profile(其它项保存后会自动更新),如下图



 

b、依赖包更新

此步骤不通过Cocoapods插件实现,直接通过命令处理。增加构建步骤——Execute shell,添加以下代码:

export LC_ALL="en_US.UTF-8"
cd ${WORKSPACE}/xxx/
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update

 

c、Xcode编译

增加构建步骤——Xcode,如下配置:

Configuration可选择Debug或Release(其中ipa打包不选中,后续通过命令行实现),



 配置证书和keychain,



 高级选型,注意通过Cocoapods依赖必须指定Workspace File文件,



 

d、Xcode打包

此步骤不通过Xcode插件实现,直接通过命令处理。增加构建步骤——Execute shell,添加以下代码(其中${BUILD_ID}为本次构建ID):

rm -fr ${WORKSPACE}/build/*ipa
xcrun -sdk iphoneos PackageApplication -v ${WORKSPACE}/build/Release-iphoneos/xxx.app -o ${WORKSPACE}/build/xxx-${BUILD_ID}.ipa

 

四、遇到问题

1、直接拉取代码之后,命令行找不到scheme问题处理

详见:http://sailqi.iteye.com/admin/blogs/2283188

 

2、使用Xcode插件打包失败

Xcode插件选中ipa打包之后,会自动把sign参数加上(暂不知道如何去掉),导致失败,通过直接用命令行打包解决该问题。

 

五、参考资料

如何在Mac OS X上安装 Ruby运行环境:http://www.cnblogs.com/daguo/p/4097263.html

最新版 CocoaPods 的安装流程:http://www.tuicool.com/articles/7VvuAr3

Cocoapods降低版本及卸载:http://www.meetrue.com/archives/133

在Mac mini上架设Jenkins服务器来运行iOS测试:http://linjunpop.logdown.com/posts/162202-set-up-jenkins-server-on-the-mac-mini-to-run-ios-tests

Jenkins整合XCode详解:http://www.pluto-y.com/jenkins-xcode-configuration/

一步一步构建iOS持续集成:Jenkins+GitLab+蒲公英+FTP:http://www.jianshu.com/p/c69deb29720d

Keychains and Provisioning Profiles Plugin官方配置文档:https://wiki.jenkins-ci.org/display/JENKINS/Keychains+and+Provisioning+Profiles+Plugin

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326804228&siteId=291194637
Recommended