Continuous Deployment of iOS Apps with Jenkins and TestFlight

Posted by by

I thought it was about time I should put together a simple guide on using Jenkins to build your iOS application – and for those of us that use the awesome testflightapp.com website for managing our iOS app distribution for testing, I have included details on creating a Jenkins job to publish the latest successful artifact to testflightapp.com.

Getting Started

I assume that anyone wanting to try this tutorial out already has an iPhone developer account with Apple and an iOS Xcode environment already setup.

The Sample iOS Project

I have created a simple iOS project that you can download from github @ https://github.com/shinetech/jenkins-ios-example. Clone it where ever you wish however I will assume you have installed it at “~/dev/iphone/jenkins-ios-example” for the tutorial.

This project has 2 targets one for the app and the other to execute our unit tests.

The project will try to use whatever default provisioning profile you have installed for “iPhone Developer”. Its best just to have a Team Provisioning Profile installed which has an application identifier of * to let you build and deploy anything for test purposes.

Installing the XCode plugin for Jenkins / Hudson

You are going to have to install the XCode plugin for Hudson CI that was created by Ray Hilton to allow you to build your iOS project from Jenkins. You can download the latest snapshot of the plugin @ http://rayh.com.au/xcode-hudson-plugin

Install the Git plugin for Jenkins / Hudson

For this tutorial you will also need to install the “Git Plugin” as we will be referencing an example git project on github. More details can be found @ http://wiki.hudson-ci.org/display/HUDSON/Git+Plugin

If you require any details on how to install Jenkins or on how to install plugins you can find all that information @ https://wiki.jenkins-ci.org/display/JENKINS/Plugins.

Ruby will need to be installed wherever the job is going to run

We need ruby to be installed wherever the iOS Jenkins job is going to be executed, to enable us to generate the correct junit test output that Jenkins is going to understand. (see below about setting up an OSX node)

Setting up your first Jenkins iOS job

Create a new Jenkins job. Lets call it “first-ios-app” (make sure the name you choose doesnt have spaces, trust me its easier!) and select “Build a free-style software project” as your job type. Setup your “Source Code Management” Set URL of Repository to be “git://github.com/shinetech/jenkins-ios-example.git“ Branch to build should be “*/master“ Click on “Add build step“. If you have the Xcode Hudson plugin installed successfully you should be able to select “Xcode” (If not then the plugin was not installed correctly). Target “JenkinsIOSExample“ Configuration “Debug“ Check “Updated version with build number”, “Clean before build” and “Build IPA“ Click on “Add build step” but this time click on “Execute shell” as we want to setup our Unit Test target Enter the following command “xcodebuild -target JenkinsIOSExampleTests -configuration Debug -sdk iphonesimulator4.3 | ./ocunit2junit.rb“ Remember earlier I said dont create your Jenkins job name with spaces well the above command is why. Using ${WORKSPACE} will give you the absolute URL path to the current workspace … however it will NOT escape spaces. All we are doing above is excuting xcode from the command line and sending its output to the excellent ocunit2junit.rb script created by Christian Hedin. Which converts the ocunit test output into the same xml format that is used by junit. Under “Post-Build Actions” Lets archive the artifacts that have been successfully built and that we will us later to deploy to testflightapp.com. So in “Files to archive” specify “build/Debug-iphoneos/*.ipa“ Check “Publish JUnit test result report” and for “Test reports XMLs” specify “test-reports/*.xml“.