iOS CI/CD: Continuous Integration and Continuous Delivery Explained
Tags: cicd, softwareengineering
Published: 2019-10-01 13:06:08

<!-- wp:paragraph -->
<p>Continuous integration and continuous delivery (<a href="https://semaphoreci.com/cicd">CI/CD</a>) is widely used by development teams, even in open-source communities. It offers a sustainable way to test and deploy code many times a day without the hurdle of doing it manually.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this guide, you'll learn the foundations of getting started with CI/CD for iOS. We'll learn about:</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>The importance of CI/CD for iOS developers</li><li>Principles of iOS CI/CD</li><li>The top benefits of CI/CD for iOS</li><li>Best practices to remember for iOS CI/CD</li><li>An iOS CI/CD workflow example</li><li>Getting started with CI/CD for iOS</li><li>Choosing the right iOS CI/CD platform</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>By the end of this article, you’ll be able to evaluate your current workflow, adopt the best CI/CD practices, and ship your iOS applications faster.  </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>The importance of CI/CD for iOS developers</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>CI/CD for iOS<strong> will save you days</strong>&nbsp;of preparing app submissions, fixing critical bugs, and uploading screenshots to the App Store. Automating these processes means that any member of the team will be able to release bug fixes or updates. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The CI/CD can check in and check out source code so all members on your team will be on the same page. Leading to better communication, increased app development quality, and more frequent releases. </p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>The DevOps Role</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>DevOps is a cultural change in the organization where the operations and development teams join forces to <a href="https://semaphoreci.com/blog/2017/07/27/what-is-the-difference-between-continuous-integration-continuous-deployment-and-continuous-delivery.html">continuously deliver</a> high-quality software.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Because teams employing DevOps ideals are focused on delivering value to users as quickly and efficiently as possible, <a href="https://semaphoreci.com/continuous-integration">continuous integration</a> and delivery is a natural extension of their operations.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The end goal is to help iOS developers build and release apps at high velocity by defining a process for effective app delivery.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Principles of iOS CI/CD</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>One of the most important aspects of implementing CI/CD for iOS is learning about the principles that can increase the value of your current workflow:</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Use Static Code Analysis</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>So that the build can fail early (in the event of serious coding errors), static code analysis should be the absolute&nbsp;<strong>first step in the build process</strong>. This way, you can fix the issues as soon they are found by the server.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Keep the Code Deployable</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Once the <a href="https://medium.com/dailyjs/why-you-should-always-use-a-linter-and-or-pretty-formatter-bb5471115a76">linter</a> step is passed, we can move on to the building and compiling of the source code. The last step in the app build process should be to generate the archive to be submitted to <a href="https://itunesconnect.apple.com/login">iTunes Connect</a>. In the case of iOS, it should be an IPA file.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Notify your Team</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Any developer can deploy any version of the app to any environment at a push of a button. Once the build is finished, it’s important to send a notification to other developers with the status of the build. This can be an email, Slack message, or similar notification service. The <a href="https://semaphoreci.com/blog/cicd-pipeline">iOS CI/CD pipeline</a> should trigger this notification at the end of every build.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Design for Iterative Releases</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Have a well-defined pipeline that focuses on automated delivery. Implement static analytics on your source code to detect issues or crashes (even in production).</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>The top benefits of CI/CD for iOS</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Aside from making your previous iOS development process more efficient, implementing a CI/CD pipeline helps your team:</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>1. Build faster</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>A continuous and automated development cycle helps mobile development teams make high-value releases faster. </p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>2. Detect problems early</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>A continuous integration pipeline can run test suites on every code change. Thus, problems can be spotted before they can reach production.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>3. Provide effective feedback </h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In a continuous integration workflow, the entire team can view and monitor source code activity. When new problems appear, the team members that introduced the failure are automatically notified. </p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>4. Automate the testing process </h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Manually testing iOS apps on a simulator or multiple devices is a time-consuming process. In a CI/CD workflow, the process is automatic and straightforward. Simply configure the devices and simulators into the server workflow and let your pipeline do the work for you.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>5. Build deployment logs</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In a CI/CD pipeline, all build deployments are logged. This means that at any given time, you can identify the exact point where your app failed.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Best practices to remember for iOS CI/CD </h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>When implementing a CI/CD workflow for iOS development, it's vital you adhere to standard best practices. Why? The guidelines below are designed to help you push high-quality code with every release.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>1. Keep your Pipeline Fast</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Always improve the quality of your pipeline by inspecting its configuration, improving build times, removing any unnecessary code or assets, configuring the right environments, and removing any bottlenecks causing issues on the deploy process.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>2. Run Code Analysis Early</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Fail fast: Include unit tests and linters early in the pipeline.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>3. Separate Build Configurations</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Use profiles to separate build configurations. Internal and testing builds are different from the builds for your users. By default, an iOS app includes Debug and Release build configurations. It makes sense to add Test, Staging and Production builds.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>4. Automate Your Builds</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Compiling and building an iOS app takes a great deal of time. Using CI/CD workflow you can automate the process and save time.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>5. Deploy Only Through the Pipeline</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The pipeline is configured to help and enforce best practices of CI/CD for your development cycle. Avoid at all cost manual deploys. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Making your code run through your pipeline requires each change to conform with your code standards and styles. This mechanism safeguards your codebase from untrusted code.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>6. Maintain Similar Environments</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If possible, try to maintain similar pipelines in all your environments. Changes that pass the requirements of one environment should pass in another. This also includes feature branches.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>7. Monitor the Pipeline</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Apps are unpredictable. No matter how cool you think your code is, the app can fail for a lot of reasons. Therefore, you'll need to proactively monitor your deploys throughout the pipeline so you can catch problems before they reach the App Store.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>An iOS CI/CD workflow example </h2>
<!-- /wp:heading -->

<!-- wp:image {"id":11914,"linkDestination":"media"} -->
<figure class="wp-block-image"><a href="https://s2blog.wpengine.com/wp-content/uploads/2019/09/ios-workflow-raw-745d17ba224c10f71963a21bee42c7d1803a2f649a810472de4576e65056e892.png"><img src="https://s2blog.wpengine.com/wp-content/uploads/2019/09/ios-workflow-raw-745d17ba224c10f71963a21bee42c7d1803a2f649a810472de4576e65056e892-1024x512.png" alt="example iOS ci/cd pipeline" class="wp-image-11914"/></a></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>After understanding and adopting essential CI/CD principles, the next step is to set up your pipeline. One of the more painful parts of iOS development is iterative releases. It's tedious and time-consuming. The role of CI/CD here is to automate all of these steps.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Before implementing CI/CD, a typical release to the App Store looks like this:</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Check out source code from some remote repository (GitHub, Bitbucket, GitLab, etc.).</li><li>Do some static analysis of the code using SwiftLint, for example.</li><li>Compile and build your iOS app in a simulator or device to check that everything is running as expected.</li><li>Run unit, UI or other kinds of tests.</li><li>Code signing and archive your app.</li><li>Submit your app to iTunes Connect.</li><li>Notify users about your release.</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>This process can be error-prone; you may experience merge conflicts and poor management of versions (as this is done manually by each developer). </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Fortunately, we can improve it with automation. When we use an iOS CI/CD pipeline, our workflow looks more like this:&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Code the application changes with Xcode.&nbsp;</li><li>When the code is ready for integration, it automatically pushes to a Git repository.&nbsp;</li><li>Next, CI triggers the execution of test cases that will confirm the code is ready for release.&nbsp;</li><li>Finally, the release pipeline triggers to deploy the archive produced in the CI stage, and a build is released with TestFlight.</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>See how the iOS developer has far less to do with CI/CD? That’s the beauty of automation.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Getting Started with iOS CI/CD </h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To integrate CI/CD into your iOS development process, start by exploring what things can make your team's job easier. You need to understand and collect information about your current workflow and provide feedback to the team until you have defined a process for your pipeline. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Using this information, your team can evaluate and define how to automate the current workflow to lead to a better development lifecycle. Optimizing and automating the current process should be the priority.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Ultimately, this approach&nbsp;<strong>increases transparency through all your team</strong>. When your iOS CI/CD pipeline is set up, your entire team will know what’s going on with the builds and will receive the latest results of tests, which means they can move on to resolving new issues. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This process allows developers to stay focused on writing code and observing the app's behavior. Meanwhile, product stakeholders have  access to updated metrics. Code changes and tests are available for review at any time.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The lesson here is that, as a faster feedback loop emerges, each member of the team can learn from each other and take responsibility for the code that is shipped.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Choosing the Right iOS CI/CD Platform</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Self-hosted CI/CD&nbsp;solutions</strong> require owning hardware and setting up infrastructure. Maintenance becomes a big endeavor.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Software-as-a-service (SaaS) solutions, on the other hand, offer cross-platform capabilities with zero maintenance</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>These<strong> cloud-based CI/CD tools</strong>&nbsp;are easy to set up and all the hardware and software maintenance is managed by the service provider. Developers can skip a lot of tedious or repetitive tasks, such as code signing and publishing.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Cloud-based CI/CD also comes with a big advantage:&nbsp;<strong>it unifies your team around a single platform</strong>, mobilizing your iOS, Android and web developers within a consistent tool.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Summing Up</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>A well-defined process and the right CI/CD tools will make  your iOS development cycle faster and more efficient.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you want to explore CI/CD for iOS in a more hands-on way, check out our tutorial on <a href="https://semaphoreci.com/blog/tutorial-ios-cicd">building, testing, &amp; deploying an iOS App with CI/CD</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Have any questions about this guide? Don't hesitate to reach out to us on Twitter <a href="https://twitter.com/semaphoreci">@semaphoreci</a>.</p>
<!-- /wp:paragraph -->