A Comprehensive Guide to use Azure CI/CD for iOS Apps

Learn how to use Azure pipeline for building and deploy iOS apps

Ahmad G. Sufi
Level Up Coding

--

How does a large iOS team work together to produce a large and complex app? how do multiple developers work together on the same code base? without overriding and destroying each other’s code and how does a developer add his/her code without accidentally destroying some functionality in the app.

Some points must be taken into consideration before working with a team:

Question: how do multiple developers work together on the same project?

Answer: Source Control.

Question: how does a developer ensure his/her code doesn’t break the project?

Answer: Unit Test.

Question: how do multiple developers follow same coding style and maintain a consistent style of coding?

Answer: using Lint Tool.

Question: Who is responsible for uploading the build?

Moreover, there are some points that must be taken into consideration before uploading any build:

  1. Pull the latest code and merge changes.
  2. Download dependencies and make sure all of them are up to date.
  3. Run all unit tests and make sure all still pass.
  4. Run the lint tools and fix any code that doesn’t follow the style guide.
  5. Download the p12 certificate.
  6. Download and match the provisioning profile.
  7. Build, clean, archive.
  8. Send the IPA file and attach a release note.

Who is in charge of running these tools and proceed in the team?

well, fortunately, we don’t need someone to do this, and this is where something called a CI/CD.

Before diving in any further, let me introduce a few common terms:

DevOps: Software development approach which involves Continuous Development, Continuous Testing, Continuous Deployment, Continuous Monitoring throughout it is development lifecycle.

Continuous Integration (CI): compile, validate, code review, Unit testing, integration testing

Continuous delivery (CD): deploying the build application to test server, and perform UAT.

Continuous deployment (CD): deploying the tested application to prod server for release.

After I uploaded the project to the azure Source Controller and enabled pipeline, I’m going to show you how to practice everything we have talked about.

CI Triggers

specify the events when you want to run the pipeline. YAML pipelines are configured by default with a CI trigger on your default branch (which is usually master). You can set up triggers for specific branches or for pull request validation. For a pull request validation trigger just replace the trigger: step with pr: as shown in the two examples below.

Here I’m going to trigger any branch starting with releases

Hosted agents

To build your code or deploy your software using Azure Pipelines, you need at least one agent. As you add more code and people, you’ll eventually need more.

Here I’m going to use a self-hosted macOS agent without any customization, you can use Linux agent, Windows agent, Docker agent.

Install certificates and provisioning profile

To sign your application you will need to install the certificate and provisioning profile that we have already imported into the Azure dashboard as a Secure-Files

Then after you had the signing, you should exclude the pod file from code signing by adding this code at the end of your pod file in case you have any dependency in your project:

Before running if you have any dependencies, make sure to be downloaded before hitting to build stage.

CocoaPods task

This task optionally runs pod repo update and then runs pod install.

Build an environment

You can use Azure Pipelines to build your apps with Xcode without needing to set up any infrastructure of your own. Xcode is preinstalled on Microsoft-hosted macOS agents in Azure Pipelines. You can use the macOS agents to run your builds.

here is the YAML snippet for clean build analyze the app and packaging

Copy Files task

Use this task to copy files from a source folder to a target folder using match patterns.

Publish Build Artifacts task

Use this task in a build pipeline to publish build artifacts to Azure Pipelines, TFS, or a file share.

So now the IPA file attached to the Artifacts file and it’s ready to publish, you can use distribution tools like:

  1. TestFlight
  2. App Store
  3. AppCenter
  4. Fabric
  5. hockeyApp

and more …

I’m going to use AppCenter to publish the IPA file.

App Center Distribute task

App Center Distribute is a tool for developers to quickly release builds to end-user devices. Distribute supports Android, iOS, macOS, UWP, WPF, and WinForms apps, allowing you to manage app distribution across multiple platforms all in one place. With a complete install portal experience, Distribute is not only a powerful solution for beta app tester distribution but also a convenient alternative to distribution through the public app stores. Automate your distribution workflow even further with our App Center Build and public app store integrations. Upon the completion of a successful build, automatically submit your app release to TestFlight, Apple App Store, Google Play.

Use this task to distribute app builds to testers and users through App Center.

So know the IPA file successfully published by App Center and all testers notified with release note that you have entered.

Integrate with service hooks

Service hooks let you run tasks on other services when events happen in your Azure DevOps projects. For example, create a card in Trello when a work item is created or send a push notification to your team’s mobile devices when a build fails. You can also use service hooks in custom apps and services as a more efficient way to drive activities when events happen in your projects.

What is a service hook?

Service hook publishers define a set of events. Subscriptions listen for the events and define actions to take based on the event. Subscriptions also target consumers, which are external services that can run their own actions, when an event occurs.

I’m going to integrate with the Microsoft team, for more details on how to set up your service hook

That’s it! After now let’s focus on the code 📈 💻 and let CI/CD do everything 🚀 .

If you have any questions or comments on this tutorial, do not hesitate to contact me: Linkedin, Twitter, Email: alsofiahmad@yahoo.com.

Thanks for reading!😀

References

--

--