Jenkins iOS – Git, xcodebuild, TestFlight
Introduction with Jenkins iOS
If you are new to continuous integration for mobile platforms then you are in the right place. This article will explain how to setup a fully automated continuous integration environment. To do this we will use the following:
- Jenkins: Our Continious integration server application
- Git: Our code repository,
- TestFlight: Our mobile testing distribution platform and each popular mobile platform
- XcodeBuild: The build tool for iOS
The life cycle of a build will look like this:
- Developer commits and pushes their changes to the Repo
- Jenkins iOS Server Job monitors Git Repo and triggers a build on the developer commit
- Jenkins iOS Server Job executes the Build Scripts (XcodeBuild) checked in to the Repo
- Jenkins iOS Server Uploads completed build to TestFlight
As you can tell by the workflow above, Jenkins is pretty much the orchestrator of this process. Jenkins essentially replaces the developers duties of building, checking for errors, running unit/functional/integration tests and publishes those builds out to the business or end users. Hence, the name Jenkins.
Get Jenkins Installed on a Server Environment
Step 1: Download Jenkins Server.
Step 2: Install Jenkins
As noted before Jenkins is build on the Java Run-time. You will need to install the Java Runtime if your system doesn’t already have it installed.
Jenkins iOS will install a daemon that will allow it to run on it own, whether someone is logged in or not. Jenkins installer will create a user called Jenkins. It is recommend that you follow these setup to ensure the Jenkins user is correctly configured:
- After installing Jenkins go to into system preferences –> Group and Users.
- Unlock the panel. Give the “Blank” user a full name so you recognize them.
- Change the password to something you know.
- Grant the user admin rights. Here is a how-to grant admin rights tutorial.
- Log off the current user and log in using Jenkins. Finish this tutorial while logged in with Jenkins user.
Setup 3: Open the dashboard
You will setup and manage Jenkins iOS using a browser that points to a website URL. Typically it will be accessible via http://localhost:8080 while you are on the machine Jenkins iOS is installed.

Get Jenkins iOS Setup

Jenkins out of the box is fairly vanilla. This is good since it allows for it to be customized. Customization comes in the form of Plugins. For this tutorial, we are going to need the following Plugins:
- Git Plugin: This will allow Jenkins to Monitor and pull code from our git repositories that will in turn trigger the build.
- TestFlight Plugin: This will streamline the post build upload process for submitting your ipa files to TestFlight.
- Xcode Plugin: This plugin allows Jenkins to call Xcode command line tools.
Setting up the server
Configuring Jenkins
Most of the default setting in the root Dashboard –> Manage Jenkins –> Configure System section is sufficient to get started. However, some routines, such as the xcodebuild, relay on xcode being installed. So you will need to ensure Jenkins execution context has any necessary environment setup.
Create a Jenkins Job
This is usually done after everything has been setup. For the purposes of this tutorial, we will have an initial job setup in advance.

Select New Job –> Enter a Job Name –> Select Build a free-style software project
This will give use vanilla Jenkins job that we can customize our CI process with our desired plugins.

Using the Git Plugin
In order to use the Git Plugin, your build server needs to have Git installed. For Mac, this comes installed along with XCode. If not, you should: Open terminal –> Execute command xcode-select --install
Step 1: Install and Enable Git Plugin
At the Root of the Jenkins website Select Manage Jenkins –> Select Manage Plugins

Select the Available Tab, Type Git in the search, Check the box and install/restart Jenkins.
Step 2: Setup Source Control Management Settings
The purpose of this setup is to perform a git Clone command on your configured Repository and the designated branch. This will pull down the latest commit locally so the build can be invoked.
Using the Job that was created earlier we will configure it’s Source Control Management section to use Git. Starting at the Jenkins Dashboard you should see you list of Jobs created. Click on iOS Job –> Then click on Configure on the left pane menu.

The 2.0 Version of this plugin seems to fail setting credentials on a mac. You might see this error when setting up
could not lock config file .git/config. I used the 1.5 version over the 2.0 because of this BUG. You can find the git plugin version 1.5 here.
The 1.5 version of the Git Plugin doesn’t support credentials (only SSH). So it order to get this to work with a username and password I needed to pass the credentials via URL like this:https://username:password@github.com/you/example.git
At this point, if you execute your job then Jenkins should perform a fetch against your configured Git repository and clone the project files into the job’s workplace (which should be: {Jenkins Home Folder}/jobs/<Your Job Name>).
So, give it a try.
Step 3: Add and Setup SCM Polling
In the Build Triggers section of the Job Configuration screen you will be able define the polling Interval. These configuration accepts cron syntax to define the polling schedule.
Simply Check the Poll SCM check box and define your cron schedule. Below illustrates a 5 min polling (this is too often of a schedule to run all the time but for tutorial and testing purposes it is acceptable).

Ideally, I would like to use a Git Hook to push a trigger to Jenkins but unfortunately I am using TFS with a Git bridge interface that doesn’t support Git hooks. So, I am subjected to polling for changes.
If you would like for information about setting up a Git Hook to trigger Jenkins builds Kohsuke Kawaguchi wrote a great post on this.
At this point, if you do a commit to your repository Jenkins will identify the change execute the Job.
Go ahead, give it a try.
Step 4: Add and Setup Build Step – iOS Job
This assumes your build environment has xcode, xcodebuild tools, provisioning profiles and necessary certifications installed.
The shell script I have written below performs a clean, run a build, create an signed archive and an exported ipa for adhoc deployments.
Navigate in finder or terminal to your job’s workspace (something like ~/jobs/{your Job Name}/workplace.
Create a file called iOS_Build.sh
Copy the script below into your newly create iOS_Build.sh file while replacing your project specific information (PROVISIONING_PROFILE, CODE_SIGN_IDENTITY, exportProvisioningProfile name and an appropriate name for your xcarchive/ipa files)
Create the following directories ./JenkinsBuild, ./JenkinsArchiveand./JenkinsIPAExport`.
xcodebuild -alltargets clean
rm -rf "./JenkinsBuild/*"
xcodebuild -target HelloJenkins PROVISIONING_PROFILE="00000000-0000-0000-0000-000000000000" CONFIGURATION_BUILD_DIR=JenkinsBuild
rm -rf "./JenkinsArchive/*"
xcodebuild -scheme HelloJenkins archive PROVISIONING_PROFILE="00000000-0000-0000-0000-000000000000" CODE_SIGN_IDENTITY="iPhone Developer: Justin Hyland (XXXXXXXXXX)" -archivePath ./JenkinsArchive/HelloJenkins.xcarchive
rm -rf "./JenkinsIPAExport/*"
xcodebuild -exportArchive -exportFormat IPA -exportProvisioningProfile iOS\ Team\ Provisioning\ Profile:\ com.yourAPP.HelloJenkins -archivePath ./JenkinsArchive/HelloJenkins.xcarchive -exportPath ./JenkinsIPAExport/HelloJenkins.ipa
If you get this error error: can't exec '/Developer/usr/bin/xcodebuild' (No such file or directory) you many need to run the following command in the terminal:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Execute this script via terminal while in your job’s workspace directory: sh iOS_Build.sh
I would recommend running each xcodebuild command one at a time to help ease any troubleshooting required.
If you where prompted for a password during the code signing/archiving command then you will need to change your certificate’saccess control settings.
Open Keychain Access
Click System and My Certificates in the left hand side of the window and Click the lock to unlock the system keychain.
Expand your iOS certificate to expose your private key and Double Click the key.
Click Access Control tab and ensure Allow all applications to access this item is selected.
Click Save Changes

If you where prompted for a password during the build script execution, try it again to make sure you are not required to enter a password.
Once your build is successfully simply add a new Execute Shell command build step in Jenkins and enter sh iOS_Build.shand your done.

Step 5: Add and Setup Post Build Step – Jenkins iOS TestFlight Upload
TestFlight is a great way to distribute beta and internal applications. I have used it with great success. Likely, there is a Jenkins Plugin to upload your automated builds.
Once you have created a TestFlight account the configuration is simple. Navigate to the TestFlight API Doc page and get yourAPI_Token and your Team_Token.
You token pair needs to be setup in: Jenkins Dashboard –> Configure System –> Scroll to TestFlight section, Enter your tokens and Click Save.
Back to the Jenkins iOS job. All you need to do is Select your Token pair setup previously and enter your .ipa file location (relative to your job’s workspace folder). Additionally, you can setup a distribution list on TestFlight for sending out notifications via Jenkins upload. After you setup a distribution list on TestFlight, supply that name in the advanced section of the Jenkins Plugin. Now you have email notifications via TestFlight.

Jenkins iOS – Git, xcodebuild, TestFlight的更多相关文章
- Jenkins+Maven+Git CI环境搭建手册
Jenkins+Maven+Git CI环境搭建手册 环境: OS:Linux version 2.6.32-220.23.2.ali878.el6.x86_64 (ads@kbuild) (gcc ...
- Jenkins+maven+git+sonar 系统持续集成&代码单測管理
Jenkins+maven+git+sonar 系统持续集成&代码单測管理 Jenkins的安装 Jenkins是基于Java开发的一种持续集成工具,用于监控持续反复的工作.功能包含: 1.持 ...
- 老李分享:持续集成学好jenkins之Git和Maven配置
老李分享:持续集成学好jenkins之Git和Maven配置 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...
- 老李分享:持续集成学好jenkins之Git和Maven配置 1
老李分享:持续集成学好jenkins之Git和Maven配置 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...
- Jenkins获取git tags代码
配置Jenkins获取git tag代码的方式其实方法很多,目前我使用比较多的主要是通过Git Parameter 来配置动态的获取最新tags代码,主要我们首先需要安装一下Git Parameter ...
- Jenkins通过git tags进行回滚代码
配置Jenkins获取git tag代码的方式其实方法很多,目前我使用比较多的主要是通过Git Parameter 来配置动态的获取最新tags代码,主要我们首先需要安装一下Git Parameter ...
- Jenkins-在windows上配置自动化部署(Jenkins+Bonobo.Git.Server)
本文配置Jenkins.git服务器采用 Bonobo.Git.Server 1. 登录后,打开Jenkins界面,新建一个任务 2. 配置信息 3. 配置git项目地址,我们先进行其他配置,等会再继 ...
- linux服务器使用Jenkins+gradle+git打apk包,报错Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
linux服务器使用Jenkins+gradle+git打apk包,遇到的错误Gradle build daemon disappeared unexpectedly (it may have bee ...
- Jenkins+Gradle+Git自动打apk包,并上传到ftp
软件安装: 1.安装Jenkins.git.AndroidSDK 2.配置AndroidSDK环境变量 ANDROID_HOME:D:\Androidsdk PATH:%ANDROID_HOME%\p ...
随机推荐
- 登录超时自动退出,计算时间差-b
// 此方法适用于所有被创建过的controller,且当前controller生命周期存在,如有错误的地方望大神斧正 // 说一下我们的需求和实现原理,需求:在点击home键退出但没有滑飞它,5分 ...
- ffmpeg 编码
编码可以简单理解为将连续的图片帧转变成视频流的过程.以H264为例给出编码的代码: int InitEncoderCodec(int width, int height) { auto enc = a ...
- BAT CMD 批处理文件脚本 -2
http://checheng1988.blog.51cto.com/4725808/1090733 在很多windows程序中会见到很多用扩展名为.bat和.cmd结尾的文件,那么这些文件能干什么呢 ...
- EXT--表单AJax提交后台,返回前端数据格式的转换
前言: 前端发送请求至服务端(Java),得到的数据是Java语言对象所表现的形式,经常需要转换为JSON格式的字符串写出至前端:当前端获取后也往往需要将字符串转换为js的对象.本文描述了在EXT作为 ...
- GhostDoc:生成.NET API文档的工具 (帮忙文档)
在 Sandcastle:生成.NET API文档的工具 (帮忙文档) 后提供另一个生成API文档的工具. 1) 准备工作 安装GhostDoc Proc. 收费的哦.... 这个工具的优势是不像 ...
- Roy Li的学习和成长自传
我不知道自己是什么时候从哪里来到这个世界上的,也许是石头里蹦出来的,也许是女娲捏出来的,上帝造出来的.上溯到我记忆的最前端,抱着我的好象 是一个女人,穿着白衣服,白得象石灰一样的那种.以至于后来我被告 ...
- MethodInvoker 委托
MethodInvoker 提供一个简单委托,该委托用于调用含 void 参数列表的方法. 在对控件的 Invoke 方法进行调用时或需要一个简单委托又不想自己定义时可以使用该委托. 下面的代码示例演 ...
- 跨线程调用控件之MethodInvoker
原文:http://www.cnblogs.com/cm8448940/archive/2008/07/10/1240045.html 使用到两个控件,一个按钮button1,一个标签label1. ...
- linux源代码阅读笔记 linux文件系统(转)
linux文件系统: 操作系统的文件数据除了文件实际内容外,还有非常多的属性,如文件权限(rwx)与文件属性(所有者.群组.时间参数等). 文件系统通常将这两部分数据存放在不同的块.权限属性放 ...
- ASP.NET MVC 3 Razor 视图引擎 基本语法
本篇博文将进入MVC 3 的世界了,首先学习一下MVC 3 新增的Razor视图引擎的基本语法. 1. 使用 @ 字符将代码添加到页面中.正如传统的aspx视图的<% %>相同. ...