美文网首页持续集成iOS 持续化集成iOS备忘录
基于Jenkins的CocoaPods化iOS项目构建+蒲公英/

基于Jenkins的CocoaPods化iOS项目构建+蒲公英/

作者: nimomeng | 来源:发表于2016-08-26 22:50 被阅读1698次

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

准备工作

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

Jenkins下载页面

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

java -jar jenkins.war --httpPort=8888

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

Jenkins 运行状态
http://localhost:8888

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

配置工作

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

插件界面

以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名后,选择第一项:构建一个自由风格的软件项目

Paste_Image.png

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

Jenkins配置 part1

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

Jenkins配置 part2

CocoaPods配置

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

CocoaPods配置

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

Warning

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

XCode General配置

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

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的路径。

General Setting
配置证书

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


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文件所在路径

高级设置

开发者证书导入

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

  • 从苹果开发者官网:官网地址,导入Certificates和Provisioning Profiles证书或密钥:
    Apple Developer
    应该保证XCode的General窗口箭头位置没有黄色的惊叹号:
General

集成蒲公英发布系统:

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

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,如下图所示:

SetBuild

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

image

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

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的用户名密码。

Git选项

参数化构建

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

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

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


Git Parameter 配置

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


源码管理中git的设置

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

相关文章

网友评论

  • 羊子222:你好,麻烦问一下,怎么保证 Jenkins 里面的 cocoapods 可以用啊,我的项目里面 在 podfile 里面有很多的 source 然后执行 在Jenkins 的 shell 里面执行 pod install 的时候就报错,报没有配置用户名和密码,但其实代码是已经拉下来的,请问一下有没有遇到过这个问题啊?
    nimomeng:@羊子222 没有。
    不过你可以先给那个目录执行chmod来修改权限试试。
    其实你随便去一个有权限的目录下测试pod install就行,比如Desktop。
    关键时看pod是否被正确的安装过了。
    羊子222:@nimomeng 在jenkins的目录里面 pod install 的时候,报没有权限创建目录,你没有遇到过这个问题?:joy::joy::joy::joy:
    nimomeng:@羊子222 你看下jenkins所在环境里是否安装了cocoapods就知道啦。在命令行里输入pod install看看什么反应。
  • 谭谭谭思密达:PhaseScriptExecution [CP]\ Check\ Pods\ Manifest.lock /Users/mac/Library/Developer/Xcode/DerivedData/chuxinloans-bewnvvkjdmdbgahkngukoakyorie/Build/Intermediates.noindex/chuxinloans.build/Debug-iphoneos/chuxinloans.build/Script-99008CDF717AF5228415C3EF.sh
    cd /Users/mac/.jenkins/workspace/MiQian_Debug
    /bin/sh -c /Users/mac/Library/Developer/Xcode/DerivedData/chuxinloans-bewnvvkjdmdbgahkngukoakyorie/Build/Intermediates.noindex/chuxinloans.build/Debug-iphoneos/chuxinloans.build/Script-99008CDF717AF5228415C3EF.sh
    error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

    ** BUILD FAILED **

    The following build commands failed:
    PhaseScriptExecution [CP]\ Check\ Pods\ Manifest.lock /Users/mac/Library/Developer/Xcode/DerivedData/chuxinloans-bewnvvkjdmdbgahkngukoakyorie/Build/Intermediates.noindex/chuxinloans.build/Debug-iphoneos/chuxinloans.build/Script-99008CDF717AF5228415C3EF.sh
    (1 failure) 不太懂什么问题啊
  • 灌水iOS:+ pod install
    /Users/Shared/Jenkins/tmp/jenkins8626280385908603271.sh: line 3: pod: command not found
    Build step 'Execute shell' marked build as failure
    Finished: FAILURE

    这个是什么没有权限吗 怎么添加权限
    nimomeng:你是不是还没安装cocoapods?
  • 虫子_Gray:Verify final result code for completed build operation
    Build operation failed without specifying any errors. Individual build tasks may have failed for unknown reasons.
    One possible cause is if there are too many (possibly zombie) processes; in this case, rebooting may fix the problem.
    Some individual build task failures (up to 12) may be listed below.

    ** ARCHIVE FAILED **


    The following build commands failed:
    SymLink /Users/chongzi/Desktop/测试版/Release-iphoneos/JSPatch/JSPatch.framework /Users/Shared/Jenkins/Library/Developer/Xcode/DerivedData/ZhiYiDoctor-doquqrkgenzgnaefebppcozzlery/Build/Intermediates/ArchiveIntermediates/ZhiYiDoctorTest/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/JSPatch.framework
    (1 failure)
    这个报错怎么解决

本文标题:基于Jenkins的CocoaPods化iOS项目构建+蒲公英/

本文链接:https://www.haomeiwen.com/subject/ruyzsttx.html