How to Add Your First iOS Job to Jenkins
Tags: ci, ios, tutorial
Published: 2017-12-12 08:25:54

---
title: How to Add Your First iOS Job to Jenkins
published: true
description: Part four of our series on CI and getting started with Jenkins.
tags: ci, ios, tutorial
canonical_url: https://bugfender.com/blog/how-to-add-your-first-ios-job-to-jenkins/
cover_image: https://bugfender.com/wp-content/uploads/2017/11/bugfender-adding-ios-job-to-jenkins.jpg
---

*This article was originally posted on our [blog](https://bugfender.com/blog/how-to-add-your-first-ios-job-to-jenkins/).*

Incase you missed our first couple of posts in this series, or if you aren't sure just what Jenkins or CI is, head back and read: <a href="https://bugfender.com/blog/what-is-jenkins-and-why-should-you-be-using-it/">What Is Jenkins and Why Should You Be Using It?</a>

<hr style="margin: 40px 0;">

In order to build iOS applications you will need to run the server on a macOS machine. You could install Jenkins directly on a Mac computer, but our preferred way is to have a small Mac mini machine* in our office devoted to these tasks.

Curious how to add an Android build to Jenkins? <a href="https://bugfender.com/blog/how-to-add-your-first-android-job-to-jenkins/">Check out this article</a>.

Even though there are some server hosting options for macOS, they are not as commonly used as Android hosting options. Our solution is to run Jenkins in a Linux machine and have a macOS worker machine for the iOS builds.

(*We mention a <a href="https://www.apple.com/mac-mini/" rel="noopener" target="_blank">Mac mini</a> because it’s the cheapest macOS machine you can get. In 2017, new models started at around $499. But if you have any other Macs laying around, such as an old MacBook with 1GB of RAM or more, that will work great as well.)

<h2>How to Add a Mac Node for iOS Builds</h2>

Follow these steps to add a Mac node as a worker node to a running Jenkins server. If you’ve already done this step, skip to “Configuring iOS jobs” below to start adding a iOS build to Jenkins. 

Please note before we begin: you do not need a public IP address or open ports on the Mac node side, so it’s a perfectly suitable setup to have the Mac machine in your home or office, sitting behind a NATed network.

<h3>Step 1: Open <code>https://your-ci-server-name.com</code> on Your Browser</h3>

You will need to open a port for JNLP. JNLP is a Java protocol to serve applications to be executed elsewhere. Your worker node will download the Jenkins worker application using this protocol.

<h3>Step 2: From the Dashboard Go to <strong>Configure Jenkins</strong> > <strong>Configure Global Security</strong></h3>

Specify a <strong>Fixed</strong> port. In the example below we chose 8081, but you can choose any port between 1024 and 65535. Make sure this port is open in your firewall.

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-2-configure-global-secuirty.png" alt="" width="1200" height="863" class="aligncenter size-full wp-image-4726" />

<h3>Step 3: Create a New Node In <strong>Jenkins</strong> > <strong>Manage Nodes</strong></h3>

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-3-nodes.png" alt="" width="1200" height="863" class="aligncenter size-full wp-image-4727" />

Select <strong>New Node</strong>.

	<ul>
<li>Give it a name, for example macmini. It can be anything.</li>

	<li>Enter a Remote root directory: <code>/tmp</code></li>

	<li>Choose Launch method: <strong>Java web start</strong></li>

	<li>Add a Label: <strong>mac</strong>. (This label will be important when you need to specify where jobs should be executed each time you configure them. Using this label, you can make sure Mac projects exclusively run on your mac machine. More on this below.)</li></ul>

After saving you’ll see the newly added node in the node list.

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-4-new-node.png" alt="" width="1200" height="863" class="aligncenter size-full wp-image-4729" />

<h3>Step 4: Open the Node You Just Created and You Will Find a Command</h3>

Copy and paste this command in a terminal in your slave machine.

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-5-slave.png" alt="" width="1200" height="822" class="aligncenter size-full wp-image-4730" />

After a few seconds you’ll get the node up and running in your node list.

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-6-node-2.png" alt="" width="1200" height="821" class="aligncenter size-full wp-image-4732" />

Now your node is ready to accept build jobs!

<h3>Step 5: Download Xcode</h3>

Since you are planning to build iOS projects, you will need to download <strong>Xcode</strong>. You can find it in the app store.

Command line tools: once you have Xcode installed, open a Terminal and type:

<pre>xcode-select --install</pre>

<h2>Configuring iOS Jobs</h2>

Now that you have a Mac worker machine, you’re ready to start building iOS apps.

<strong>Step 1:</strong> Open <code>https://your-ci-server-name.com</code> on your browser and select <strong>New Item</strong>

Specify the name of the new job and select <strong>Freestyle project</strong>:

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-7-project.png" alt="" width="1200" height="863" class="aligncenter size-full wp-image-4735" />

<strong>Step 2:</strong> Make sure your build is running exclusively on the Mac machine. 

In order to do that, in the <strong>General</strong> tab, select “<strong>Restrict where this project can be run</strong>” and write mac as label expression (this label matches the one we chose for the Mac worker in the node configuration above).

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-8-restrict.png" alt="" width="927" height="89" class="aligncenter size-full wp-image-4736" style="padding: 10px; border: 1px solid #ccc;" />

<strong>Step 3:</strong> Under Source Code Management, specify the URL of your repository. 

For our example, we’re building the <a href="https://github.com/bugfender/BugfenderSDK-iOS" rel="noopener" target="_blank">Bugfender SDK sample app</a>:

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-9-sample-app.png" alt="" width="1200" height="863" class="aligncenter size-full wp-image-4737" />

<strong>Step 4:</strong> Configuring automated build triggers.

You can select automated triggers for your builds if you don’t want to have to manually trigger them. Typically, you should configure it so that a new build is done automatically for every commit or a build is done periodically (eg. nightly builds):

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-10-build-triggers.png" alt="" width="944" height="200" class="aligncenter size-full wp-image-4738" style="padding: 10px; border: 1px solid #ccc;" />

<strong>Step 5:</strong> Once the code is downloaded, we need to specify how to build it. 

In the <strong>Build</strong> section, we will <strong>Add a build step</strong> of type <strong>Execute shell</strong> and we will execute xcodebuild like this:

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-11-build-xcode.png" alt="" width="927" height="333" class="aligncenter size-full wp-image-4740" style="padding: 10px; border: 1px solid #ccc;" />

<pre>cd Example # in our example, the project is not in the root of the repository

xcrun xcodebuild -workspace BugfenderExample.xcworkspace \

    -scheme BugfenderExample \
    -sdk iphoneos \
    CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO</pre>

This will trigger a build of the application for iOS devices, similar to when you use the <strong>Product > Build for Running</strong> in Xcode.

Make sure you add the <strong>CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO</strong> bits in order to prevent Xcode from trying to sign the built application, otherwise you will need to configure your provisioning profiles and developer certificate in that machine, which makes everything a bit more complicated.

<h2>Adding Tests</h2>

If you want to run tests, you can set them up with another build step:

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-12-adding-tests.png" alt="" width="744" height="306" class="aligncenter size-full wp-image-4744" style="padding: 10px; border: 1px solid #ccc;" />

Code:

<pre>cd Example # again, we need to move directory

mkdir -p output # this directory will contain the output of the tests

xcrun xcodebuild -workspace BugfenderExample.xcworkspace \

    -scheme "BugfenderExample" \

    -sdk iphonesimulator \

    -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.0' \

    -derivedDataPath './output' \

    test</pre>

And that’s it! You’re ready to build and test our iOS sample application:

<img src="https://bugfender.com/wp-content/uploads/2017/11/jenkins-4-13-completed.png" alt="" width="1200" height="863" class="aligncenter size-full wp-image-4748" />

Looking for more information about developing apps? Check out:

<ul>
	<li><a href="https://bugfender.com/blog/top-devices-testing-ios-apps/">Top Devices for Testing iOS Apps</a></li>
</ul>

<hr style="margin: 40px 0;">

For more posts in this series, check out:

<ul>
<li><a href="https://bugfender.com/blog/what-is-jenkins-and-why-should-you-be-using-it/">What Is Jenkins and Why Should You Be Using It?</a></li>
<li><a href="https://bugfender.com/blog/how-to-install-jenkins-in-ubuntu/">How to Install Jenkins in Ubuntu</a></li>
<li><a href="https://bugfender.com/blog/how-to-add-your-first-android-job-to-jenkins/">How to Add your First Android Job to Jenkins</a></li>
</ul>

<hr style="margin: 40px 0;">

<p class="text-p">This post was edited by Sarabeth Flowers Lewis, a freelance writer and co-founder of Lewis Commercial Writing, specializing in SEO and direct response content creation. She currently works remotely with her ginger husband writing for tech, nonprofits, and real estate. See more of her work <a href="https://www.lewiscommercialwriting.com/" rel="noopener" target="_blank">here</a>.</p>

*This article was originally posted on our [blog](https://bugfender.com/blog/how-to-add-your-first-ios-job-to-jenkins/).*