Xcode Bot & Continuous Integration

10 Jun, 2014 11:06 AM
 Xcode
 iOS
 OSX
If you are an multi-developer team and would like to run integration tests as a centralized system to detect any broken functionality or if you want to run the tests against various platform versions (iOS 6.0, iOS 7.0 and iOS 7.1 for example) including running the tests on real devices, then XCode bot is for you. Xcode bot also helps in testing all phases of app development including archiving in an un-obtrusive way.

Xcode Bot provides a mechanism to integrate code continuously as it is checked-in into source repository which is polled by the bot at set intervals. It is very similar to Jenkins except that it is from Apple and works seamlessly with Apple development tools. The report of integration is available right within Xcode in addition to browser. The reports are graphically intuitive and well designed in typical Apple design style.

Xcode bot is available as part of Server app from Apple available at App Store for 19.99 US$ (Download link). In addition to Xcode Bot service, the Server App provides File Server, Web Server, Contacts Server etc. By installing Server app, any OSX installation can become OSX server. The earlier OSX server is now discontinued.

Here is a quick walk through to configure a bot for an XCode project. There are two ways to do it - from within XCode under "Product" menu or from the Server app itself with a minor configuration required from Xcode in the end to download the bot status and reports. I prefer the second approach as it has the ability to setup ssh keys while connecting to a remote source code repo like bitbucket. Otherwise, both the approaches yield the same result. 

STEP 1: Create a sample project 

I have chosen iOS 6 as deployment target specifically to allow for running two different simulators (iOS 6 and 7.1 which is the latest iOS at the time of writing). 

Project Settings

STEP 2: Upload the code to a remote repository

OSX Server app can host code as a git or svn source code repository just like bitbucket or github. I have blogged it before - "OSX Server as Source Code Repository" - on how to do it. Skip to STEP 3 if your are using Server App as source repo. if you are using any other source repo then add it to Server App as follows (Iam using bitbucket as an example) - 

-> Click on '+' add repository as shown below

Server App add repo

-> Select Connect to Git Repository (Or svn if that is the case) and fill out the details as shown below. The user name has to be git if authentication is SSH Key for bitbucket.

Connect to remote repo
-> Setup SSH Keys. The reason i have chosen the SSH keys example is because you cannot set it up from Xcode -> Create Bot option. It can only be done from Server App and later connected to from Xcode. Use PBCOPY to copy the keys

$ pbcopy < ~/.ssh/id_rsa.pub 
$ pbcopy < ~/.ssh/id_rsa

Setup SSH Keys

STEP 3 - Create bot from XCode

Now open the project in XCode and select Create Bot menu option in Product menu. Select the share option for the scheme and leave the rest to defaults. Click next and follow the self explaining options. Finally you should see the bot successfully created message with a green tick mark. if the server is not available then you would have to run the Server App to start it once and add it in xcode by selected "Add New Server" for the server dropdown on the screen shown below.

Xcode Create Bot

Note the message, the bot uses a xcode scheme to run the build and hence it needs to be shared and hence it needs to committed to source repo. In short do a commit after creating the bot to get it going.

STEP 4 - Integrate!

You can now click on the integrate now button in Log Navigator to run the first integration of the project.

Bot Result

Mine had few issues - had to commit the scheme and setup the ssk keys to bitbucket correctly. Once done it ran successfully. If none of the devices are connected, then the bot needs to be configured to run on simulators. else It fails. Also the provisioning profiles need to be copied to server at /Library/Server/Xcode/Data/ProvisioningProfiles/ if archiving in included in the build scheme and GameCenter or In-App purchase is enabled for the app.

Adios!