Create Nightly Builds of Your iOS projects from TFS

Stephen Zaharuk / Tuesday, February 12, 2013

Have you read my other article on storing your iOS projects in TFS from a Mac? If so, then you're probably wondering how you can create nightly builds of these projects.

Now you can't really use TFS to do that, as you need a Mac to build your iOS projects. Luckily there is a solution out there that allows you to do this. And its actually really simple to setup!

So first thing you need is a Mac that you can setup as your build server. Also, make sure that you have XCode installed on that machine.

Next you need to download a product called Jenkins. The simplest way to install it, is via their pkg installer here. Don't worry, its free!!

Next run the installer and follow the directions.

When its done, its going to open a browser window to the following uri: http://localhost:8080

What you're seeing here is Jenkins. 

B/c its hosted through the browser, you can access the build machine from any machine (windows or mac) as long as those machines are on the same network. You'll simply need the IP address of the machine: 

i.e something like http://[Build_Machine_IP]:8080

Now that we've got it installed, lets see how we can install TFS plugin,  create anew job, access TFS, create the script to build our project, and set it up to do it nightly!

Install the Team Foundation Server plugin for Jenkins

1. Click the "Manage Jenkins" button in the Left hand corner. (its the fourth option down)

2. Now select the "Manage Plugins" option: 

3. Click the "Available" tab. 

4. There are a LOT of options that are being displayed here. So you have to do a search for "Team Found". You should use your browsers built in search to find it. The filter box for some reason won't find it, and if you attempt to use it, the option disappears....

Check the checkbox and click the "Install without restart" button at the bottom.

5. Now you'll be brought to a screen where it says it's processing. Once it says success, you're ready to move on to the next step. Note, you do not need to restart.

Setup a New Job

1. Click the New Job button in the upper Left corner

2. You'll see the following screen:

First you'll need to specify the name of your job. In this case, i'm calling it Project1 iOS Nightly Build. 

Also, you're going to want to select the "Build a free-style software project" option from the choices below.  When you've entered the name and made your selection, press the OK button. 

3. Now you're on the configuration screen for your build job. I'll walk you down section by section on what to fill out in order to get your project setup

4. In the first section, we can modify our project name, setup a description of what this job actually does, and configure if we want to discard our older builds.  

5. Now lets setup our Source Code. You should see an option for Team Foundation Server now. If not, make sure you go back and install the TFS plugin as mentioned above. 

Server URL: You'll need to know your TFS Server url. 

Project Path:  This is the project path in TFS that you want to pull source from

Login Name: Generally you'll want to create a specific TFS user account, as opposed to just putting a team member's username in password in here. 

User Password: The password of the user specified directly above. 

Repository browser: Just leave this at Auto

6. Now lets set up a reoccurring schedule for running this build:

Check the Build periodically option. 

You should click the "?" button next to the Schedule textbox for a much better explanation, but basically you provide 5 values:

Minute (0 - 59), Hour(0 - 23), Day of Month(1 -31), Month(1 -12), Day of Week(0-7)

If you provide a '*', you're saying that every number within the range is valid. 

So in the above scenario, we're saying Every day of every month build at Midnight. 

7. Now its time to write our build script.  Click the "Add build setup" button and select "Execute Shell"

8. Now, in the "Execute Shell" you're essentially working with normal Terminal commands. One thing to note is that you do have access to a variable called "$WORKSPACE". This variable can be used throughout your commands and maps to the Project Path you specified in the Source Code Management section. 

So, for example, say my project space was: 

$/Product/Dev/iOS/Source/

And say i wanted to access my project which is at:

$/Product/Dev/iOS/Source/MyProject/MyProject.xocdproj

Well to build that project i would write the following command:

xcodebuild -project "$WORKSPACE/MyProject/MyProject.xocdproj" -target "MyProject"

If i wanted to build all targets, i would simply drop the last 2 parmeters

xcodebuild -project "$WORKSPACE/MyProject/MyProject.xocdproj"

Note: in case there are any spaces within your project path anywhere, its smart to wrap any paths within quotes.

9. What good is a nightly build, if you don't get notified for failures. Lets add a post build action to notify us of problems. Click the Add post-build action button and select "Email Notification". Then simply type in the e-mail adresses of those who should be notified. 

And thats it! You've now setup a nightly build of your product!

I hope this was helpful. 

By Stephen Zaharuk (SteveZ)