您的位置:首页 > 移动开发 > IOS开发

iOS 持续集成- Jenkins+iOS+fir+蒲公英 搭建持续集成环境

2016-06-13 15:54 435 查看
今天用Jenkins+iOS+fir+蒲公英 搭建持续集成环境,把过程记录一下。

第一步:安装Jenkins

方法一:直接去官网下载安装包

下载地址:http://jenkins-ci.org/

下载后直接点击进入安装







安装完成后在Terminal中输入命令,打开Jenkins:

open /Applications/Jenkins/jenkins.war

方法二:使用命令行安装

1.安装 home-brew(安装指导)

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

2.安装 Jenkins

$ brew install jenkins

3.启动 Jenkins

$ jenkins

4.在浏览器输入地址:

http://localhost:8080/

使用安装包安装后会自动打开,如果端口冲突那么请修改端口

defaults write/Library/Preferences/org.jenkins-ci httpPort 8888

第二步:启动Jenkins后使用浏览器访问Jenkins

http://localhost:8080/

访问成功后显示如下:



第三步:安装插件

在“系统管理” -> “插件管理”中添加如下这个插件:

Xcode integration

左边菜单栏找到插件管理



第四步:新建项目

(1)新建项目

点击左侧工具栏”新建”,

输入项目名称,

选择第一项”构建一个自由风格的软件项目”



(2)基本信息

(3)源码管理信息

如果你是用的是Git,那就请选择Git,然后输入你的仓库地址:



如果你是用的是SVN,那就请选择Subversion,然后输入你的仓库地址:



(4)自动构建时机

这里就是告诉jenkins什么时候自动构建,当然也可以不设置。



关于定时器的格式,我只能从网上摘抄一段稍微靠谱一点的说明:

This field follows the syntax of cron (with minor differences). Specifically, each line consists of 5 fields separated by TAB or whitespace:

MINUTE HOUR DOM MONTH DOW

MINUTE Minutes within the hour (0-59)
HOUR The hour of the day (0-23)
DOM The day of the month (1-31)
MONTH The month (1-12)
DOW The day of the week (0-7) where 0 and 7 are Sunday.

To specify multiple values for one field, the following operators are available. In the order of precedence,

* '*' can be used to specify all valid values.
* 'M-N' can be used to specify a range, such as "1-5"
* 'M-N/X' or '*/X' can be used to specify skips of X''s value through the range, such as "*/15" in the MINUTE field for "0,15,30,45" and "1-6/2" for "1,3,5"
* 'A,B,...,Z' can be used to specify multiple values, such as "0,30" or "1,3,5"

Empty lines and lines that start with '#' will be ignored as comments.
In addition, @yearly, @annually, @monthly, @weekly, @daily, @midnight, @hourly are supported.


举两个例子:

// every minute
* * * * *
// every 5 mins past the hour
5 * * * *


(5)构建

添加构建步骤 -> Xcode基本信息

这里Target请于Xcode项目中Target的名字对应

Clean before build设置为YES

Configuration我选择了Release(在Release的时候Archive)

.ipa filename pattern 随便起个.ipa的名字

Output directory为.ipa的输出路径,我这里设置为 ${WORKSPACE}/build/




添加构建步骤 -> Xcode证书信息

我这里是在上传至Git的项目里已经配置过证书和Provisioning Profiles。

打开Unlock Keychain

Keychain path 设置为 ${HOME}/Library/Keychains/login.keychain

Keychain password 为你钥匙串的密码




login.keychain的路径在哪?

点击”系统管理”中的”系统设置”,Xcode Build中的Keychains

注意!

如果项目使用了cocoapods,需要配置Advanced Xcode build options,设置

Schema

SDK iphoneos

Workspace File(不用加.xcworkspace)

Build output directory 也设为${WORKSPACE}/build/



(6)构建后操作

添加构建后操作步骤

1.你可以选择上传到fir:

fir的地址:http://www.fir.im/

也可以选择上传到蒲公英:

蒲公英的地址:https://www.pgyer.com/

2.你也可以选择命令行

Execute a set of scripts

Add build step

Execute shell

在Commas中输入

fir p ${WORKSPACE}/build/SinocareDevice.ipa -T #API Token#


新版fir.im的API Token获取方式见下面:



请注意,在使用该命令前请先确认安装fir-cli,安装命令如下:

Mac OS X 10.11 以后的版本, 由于10.11引入了 rootless, 无法直接安装 fir-cli, 有以下三种解决办法:

1.使用 Homebrew 及 RVM 安装 Ruby, 再安装 fir-cli(推荐)

# Install Homebrew:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
# Install RVM:
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby

$ gem install fir-cli


2.指定 fir-cli 中 bin 文件的 PATH

$ export PATH=/usr/local/bin:$PATH;gem install -n /usr/local/bin fir-cli


3.重写 Ruby Gem 的 bindir

$ echo 'gem: --bindir /usr/local/bin' >> ~/.gemrc
$ gem install fir-cli


上面的命令来自 fir.im 的工具 fir-cli,这是他们的官方使用说明

fir.im测试平台通过他自家的工具fir-cli上传ipa包:

fir p ${WORKSPACE}/build/ipa/SinocareDevice.ipa -T eb403ebb9f85de494646d86d48


蒲公英测试平台通过curl上传ipa包:

curl -F "file=@${WORKSPACE}/build/ipa/SinocareDevice.ipa" -F "uKey=b122767e218b501d0d3434f5aeb" -F "_api_key=88c9a97bc31211919eaf4bf5ba3a" http://www.pgyer.com/apiv1/app/upload[/code] 


完成,点击保存。

(7)点击立即构建

构建成功标志位置为蓝色,失败为红色。



查看fir.im,应用上传成功:



查看蒲公英,应用上传成功:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jenkins ios