基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布

本文以本地和Git为例,结合CocoaPods,简单介绍了如何用jenkins来进行CI编译并上传蒲公英和Fir生成相应二维码的流程。

准备工作

首先,去Jenkins主页下载war包进行本地编译,网址为:https://jenkins.io/index.html
这里,笔者以LTS Release的2.7.2.war包为例

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Jenkins下载页面

下好了war包后,运行War包,并设置其端口号,命令如下:

java -jar jenkins.war --httpPort=8888

运行后命令行如下图所示:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Jenkins 运行状态

http://localhost:8888

之后根据页面提示,输入密码并且创建账户后,即可打开Jenkins主页。

配置工作

配置工作里主要进行插件的安装,插件安装方法为:
系统管理 -->管理插件,选可选插件,选择对应插件后点击直接安装即可。

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 插件界面

以iOS的持续集成为例,推荐安装的插件为:

  • build timeout plugin
    This plugin allows builds to be automatically terminated after the specified amount of time has elapsed.
  • Checkstyle Plug-in
    This plug-in collects the Checkstyle analysis results of the project modules and visualizes the found warnings.
  • Credentials Binding Plugin
    Allows credentials to be bound to environment variables for use from miscellaneous build steps.
  • description setter plugin
    This plugin sets the description for each build, based upon a RegEx test of the build log file.
  • Email Extension Plugin
    This plugin is a replacement for Jenkins’s email publisher
  • Git Changelog
    Plugin creating JIRA filter URL based on commit messages containing JIRA ticket keys in the GIT history
  • GitHub Organization Folder Plugin
    Scan entire GitHub organization for buildable branches and pull requests, in repositories. See Pipeline as Code solution page for more details.
  • Gitlab Hook Plugin
    Enables Gitlab web hooks to be used to trigger SMC polling on Gitlab projects
  • GitLab Plugin
    This plugin integrates GitLab to Jenkins by faking a GitLab CI Server.
  • Gradle Plugin
    This plugin allows Jenkins to invoke Gradle build scripts directly
  • HTML Publisher plugin
    This plugin publishes HTML reports.
  • Keychains and Provisioning Profiles Management
    This plugin integrates management of keychain and provisioning files for iOS and OSX projects.
  • Log Parser Plugin
    Parse the console output and highlight error/warning/info lines.
  • Pipeline
    A suite of plugins that lets you orchestrate automation, simple or complex. See Pipeline as Code with Jenkinsfor more details.
  • Post-Build Script Plug-in
    PostBuildScript makes it possible to execute a set of scripts at the end of the build.
  • Project Description Setter
    Set the project description from a file in the workspace
  • Publish Over FTP
    Send build artifacts over FTP
  • Subversion Plug-in
    This plugin adds the Subversion support (via SVNKit) to Jenkins.
  • Timestamper
    Adds timestamps to the Console Output.
  • Workspace Cleanup Plugin
    This plugin deletes the project workspace after a build is finished.
  • Xcode integration
    This plugin provides builders to build xcode projects, invoke agvtool and package .ipa files

创建任务

在Jenkins主页点击新建,输入Job名后,选择第一项:构建一个自由风格的软件项目

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Paste_Image.png

之后进入配置页面,按照下图来进行配置:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Jenkins配置 part1

配置管理配置部分按下图填写:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Jenkins配置 part2

CocoaPods配置

选择构建–>增加构建步骤–>Execute Shell,再对应pod的代码填写进去:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 CocoaPods配置

Command里必须要的是pod install,其他视项目结构而定。例如笔者的项目由于podfile文件在子目录之中,所以先执行CD [子目录名]进入子目录再执行。

Warning

  • 在Jenkins中设置CocoaPods配置之前请务必保证本地CocoaPods可以正常工作。这里默认你的CocoaPods已经执行过了pod setup这些步骤了。
  • CocoaPods的Execute Shell一定要在XCode配置之前执行。(点击左侧的拖动bar,可以自由调整插件顺序)
  • 目前Jenkins上虽然有CocoaPods的插件,但是功能有限,不推荐使用

XCode General配置

先进行添加:选择构建–>增加构建步骤–>XCode

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Paste_Image.png

General Build Settings

在target处填写XCode项目的target名称。如果不知道名称,去项目目录下运行xcodebuild -list进行查看;
Configuration设置为Debug或者Release,取决于你想要什么样的版本;
ipa filename pattern:可以定制ipa的名称,例如yourIPAname_${VERSION}_${BUILD_DATE}
Output directory设置ipa的路径。

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 General Setting

配置证书

Code signing & OS X keychain options设置如下:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Code Siging设置

Code Sign Identity填写证书的名称(请查看你的Keychain里对应iPhone Developer证书的名称,包括括号里的内容)
unlock Keychain,在Keychain Path里填入在项目中倒入的开发者证书的keychain。如果不知道在哪儿,可以试试:

default : ${HOME}/Library/Keychains/login.keychain

Password是你的登陆密码

XCode 高级设置

XCode Schema File:如果不知道名称,去项目目录下运行xcodebuild -list进行查看;
SYMROOT:填写你想设置的SYMROOT,例如${WORKSPACE}/build/
Custom xcodebuild arguments:XCode配置参数,可以参考下图的设置
XCode Workspace File:如果需要运行workspace,请选择项目下对应的*. xcworkspace文件
XCdoe Project Directory:填写项目路径
XCode Project File:填写Project文件所在路径

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 高级设置

开发者证书导入

XCode此时应该导入开发者证书:

  • 从苹果开发者官网:官网地址,导入Certificates和Provisioning Profiles证书或密钥:
    《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Apple Developer
    应该保证XCode的General窗口箭头位置没有黄色的惊叹号:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 General

集成蒲公英发布系统:

点击增加构建步骤–>Execute shell,创建脚本窗口:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 QQ20160826-1.png

在脚本里填写如下格式代码:

curl -F "file=@${WORKSPACE}/ipa/helloJenkins.ipa" -F "uKey=xxxx" -F "_api_key=xxx" https://www.pgyer.com/apiv1/app/upload

其中,file是ipa文件的路径,记得要带@;uKey与F_api_key是蒲公英系统上的userKey与apiKey,蒲公英官网注册好后填写完全即可。

选择增加构建后操作步骤–> Set Build Description,如下图所示:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 SetBuild

在Description中填写Image的对应地址即可:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 image

点击OK,编译即可。然后进入Console页面去查看。
成功后应该如下图所示:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Paste_Image.png

集成fir.im发布系统

集成fir比集成蒲公英更加简单,因为官方有jenkins插件。直接安装后配置其apiKey即可。
参考fir官网对其的介绍页面

集成Git

取消掉XCode对应设置

如果确定要通过Git来构建,先取消掉之前的Advanced Xcode build options步骤,方法是清除Advanced Xcode build options内部的所有配置

更改源码管理

随后,回到源码管理,将选项由none改为Git,填入Git项目地址。这里以public项目为例,所有下面的credentials不用填写。如果是private,则需要填写git的用户名密码。

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Git选项

参数化构建

想要达到根据具体分支构建的目的,需要添加对应插件Git Parameter Plugin
之后进入配置页面:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 添加参数

在添加参数页面中设置 Git Parameter

之后按照下图所示进行设置:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 Git Parameter 配置

之后要在下面的 源码管理 Git配置页面中Branch的对应字段填写你在Git Parameter中Name上所写的名字,如下所示:

《基于Jenkins的CocoaPods化iOS项目构建+蒲公英/FIR系统发布》 源码管理中git的设置

希望小文能给各位的工作带来帮助!

    原文作者:nimomeng
    原文地址: https://www.jianshu.com/p/62b5ff147dac
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞