Home Articles

How to Use Jenkins to Build Your iOS App

A Beginner’s Guide to Effortless Development and Deployment. Let us discuss by step by step guide for Jenkins in this article:

Demo of Jenkins

Demo of Jenkins

A beginner’s guide to understanding Jenkins and automatically generating .ipa files.

CI/CD - Structure

CI/CD - Structure

Why CI/CD?

CI/CD (Continuous Integration/Continuous Delivery) streamlines software development by automating the integration, testing, and delivery processes, ensuring faster, more reliable, and efficient deployment of software updates. It enhances collaboration, accelerates time-to-market, and minimizes errors through automated testing and continuous feedback loops.

Jenkins Logo

Jenkins Logo

Jenkins is an open-source CI/CD tool that helps automate tasks in terms of integration and deployment. Jenkins will be able to buildtestdeploy the iOS application.

Jenkins ensures a reliable development pipeline by building the iOS application only when the associated test cases have successfully passed, maintaining the integrity and quality of the codebase.

Before getting into action, let’s understand GitHub and Webhooks.

Configuring GitHub

Go to GitHub Repository and click on Settings

GitHub Repo - Example

GitHub Repo - Example

Click on Webhooks

How to add Webhooks in GitHub

How to add Webhooks in GitHub

Click on Add webhook

Add Webhook

Add Webhook

You can select the individual events. I selected Pull Requests/Pushes. Make sure that the ‘Active’ option is checked and click on Add webhook

Events

Events

Jenkins

Installing Jenkins

Download the latest stable build from the official website. I have installed it using the HomeBrew package manager.

Once the installation is done, navigate to http://localhost:8080/ = your Jenkins local address.

Configuring Jenkins for iOS

To unwrap the password, use the following on the terminal

sudo cat /Users/YOUR_USER_NAME/.jenkins/secrets/initialAdminPassword

Terminal command - Fetch password

Unlock Jenkins

Unlock Jenkins

I have selected the ‘Install suggested plugins’ option in the next window.

Manage Jenkins

Select Manage Jenkins and then click Plugins in the options.

Manage Jenkins

Manage Jenkins

Click on Available Plugins, select Xcode Integration and install it.

Xcode Integration plugin

Xcode Integration plugin

Creating a Jenkins Job

Creating a Jenkins Job

Creating a Jenkins Job

On Jenkins Dashboard, select New Item. Select Freestyle Project and provide a name to create a job.

Integrating Version Control

Click on the Source Management

Select Git and Add your Repository URL.

Source Code Management

Source Code Management

Click on the Build Triggers to trigger the events. We can select the ‘GitHub hook trigger for GITScm Polling’ to check the webhook events.

Build Triggers

Build Triggers

Now, our GitHub repository is integrated with the Jenkins project.

With GitHub and Jenkins integration, we can trigger the Jenkins job to run with every commit.

Xcode Integration Plugin with Jenkins

Go to Build Steps → Add Build step → Xcode

Build Steps

Build Steps

In General build settings, update the necessary fields.

General Build Settings - Xcode

General Build Settings - Xcode

Check the Pack application, build and sign .ipa

Advanced Build Settings

Advanced Build Settings

If you need to enter values for advanced build settings in Xcode, you can do so by filling out the fields related to the workspace.

Advanced Build Settings

Advanced Build Settings

Move to Jenkins Dashboard > Manage Jenkins > System

This will help to configure the Xcode Builder. Add Team Name and Development Team ID.

Xcode Builder

Xcode Builder

Add Keychain and fill out valid values for Keychain Name and Keychain password.

Note: The keychain path is already present.

Keychain

Keychain

Apply the changes and save.

Use this link to fetch the member ID.

Post Build Actions

Post Build Actions

Post-build Actions

Under Post-build actions, select Set GitHub commit status (universal). Under the What: section, set Status result: to One of default messages and statuses.

After saving this, run the build

Build Now

Build Now

Build Now

Jenkins Dashboard — Successful Build

Jenkins Dashboard

Jenkins Dashboard

Console Output

Console Output

Console Output

The build is ready and .ipa has been generated successfully.

/Users/{USERNAME}/.jenkins/workspace/SampleiOSProject/build/Release-iphoneos/WeatherApp_1.2024.01.20_dev.ipa

ipa Generation

ipa Generation

Triggering Jenkins GitHub Integration with Pushes

Now we are set with the GitHub Integration, Jenkins and Xcode along with Webhook.

Let’s try the push from GitHub and check the results in the webhook requests.

Webhook.site Response

Webhook.site Response

This article introduces Jenkins and explains its integration with GitHub and the Xcode plugins.

I will cover how to automatically create Jenkins jobs for pull requests or push commits in GitHub in my upcoming article.

Automatically generated .ipa file using Jenkins

Integrating Jenkins with GitHub Pull Requests

To automatically trigger Jenkins jobs for GitHub pull requests, follow these steps:

Install GitHub Plugins

In Jenkins, go to Manage Jenkins > Manage Plugins.

Install the following plugins:

- GitHub Integration Plugin

- GitHub Pull Request Builder Plugin - Refer documentation

Create a GitHub Webhook

In your GitHub repository, navigate to Settings > Webhooks.

Add a new webhook with the Jenkins URL: http://localhost:8080/github-webhook/ and set the content type to application/json.

Choose events like “Pull request” and “Push” to trigger builds on PRs.

Configure Jenkins Job

In Jenkins, create a new job and configure it as a Freestyle Project or Pipeline.

Under Source Code Management, select Git and add your GitHub repository URL.

For authentication, use your GitHub credentials (either via OAuth or Personal Access Token).

PR Trigger Setup

In the job configuration, under Build Triggers, select GitHub Pull Request Builder.

This will enable Jenkins to listen for new pull requests and trigger builds accordingly.

Pull Request Validation

Once set up, Jenkins will automatically build the PR and post the build status (success, failure) back to GitHub, visible in the PR itself.

Integrating Code Quality Tools: SwiftLint and Danger

After setting up Jenkins with GitHub pull requests, you can also enhance your CI pipeline by adding code quality checks using tools like SwiftLint for linting and Danger for managing the code review process.

SwiftLint

SwiftLint helps in enforcing Swift style and conventions in your codebase. You can integrate SwiftLint in your Jenkins pipeline for continuous linting. Here’s the link to the SwiftLint tool:

SwiftLint GitHub Repository

Danger

Danger automates code review tasks and ensures that standards and conventions are followed in your PRs. It is commonly used to add warnings and improve the feedback process for your development team. Here’s the link to the Danger tool:

Danger GitHub Repository

To integrate SwiftLint and Danger:

  • Install the tools locally in your project and configure them to run as part of your Jenkins pipeline.

  • You can configure Danger to post messages directly on GitHub pull requests to highlight linting issues, missing documentation, and other code review-related information.

Note

Please find the GitHub Repo

This is a free third party commenting service we are using for you, which needs you to sign in to post a comment, but the good bit is you can stay anonymous while commenting.