iOS/macOS
Use a CI pipeline to build and test iOS and macOS applications.
You can build and test iOS and macOS applications using a macOS platform on Harness Cloud, a self-managed macOS VM, or a local runner build infrastructure.
The examples in this guide use Xcode. You can also use Fastlane to build and test your iOS and macOS apps.
This guide assumes you've created a Harness CI pipeline.
Specify architecture
To use M1 machines with Harness Cloud, use the Arm64 architecture.
stages:
- stage:
name: build
identifier: build
type: CI
spec:
cloneCodebase: true
platform:
os: MacOS ## selects macOS operating system
arch: Arm64 ## selects M1 architecture
runtime:
type: Cloud
spec: {}If you need to use Intel-based architecture, Rosetta is pre-installed on Harness Cloud's M1 machines. If you need to use it, add the prefix arch -x86_64 to commands in your scripts. Keep in mind that running apps through Rosetta can impact performance. Use native Apple Silicon apps whenever possible to ensure optimal performance.
To configure a self-managed macOS build infrastructure, go to Set up a macOS VM build infrastructure with Anka Registry or Set up a local runner build infrastructure.
This example uses a VM build infrastructure:
stages:
- stage:
name: build
identifier: build
description: ""
type: CI
spec:
cloneCodebase: true
infrastructure:
type: VM
spec:
type: Pool
spec:
poolName: YOUR_VM_POOL_NAME
os: MacOSIf you need to use Intel-based architecture and Rosetta is not already installed on your build infrastructure machines, you can use a Run step to install this dependency. Keep in mind that running apps through Rosetta can impact performance. Use native Apple Silicon apps whenever possible to ensure optimal performance.
Install dependencies
Use Run steps to install dependencies in the build environment.
Homebrew and Xcode are already installed on Harness Cloud macOS machines. For more information about preinstalled tools and libraries, go to the Harness Cloud image specifications.
You can add package dependencies in your Xcode project and then run Xcode commands in Run steps to interact with your project's dependencies.
Due to the long install time, make sure Xcode is pre-installed on your build infrastructure machines. If Homebrew is not already installed, use Run steps to install it and any other dependencies.
You can add package dependencies in your Xcode project and then run Xcode commands in Run steps to interact with your project's dependencies.
Cache dependencies
Add caching to your stage.
Use Cache Intelligence by adding caching to your stage.spec:
You can use built-in steps to:
Here's an example of a pipeline with Save Cache to S3 and Restore Cache from S3 steps. It also includes a Run step that creates the .ipa archive with xcodebuild archive and xcodebuild --exportArchive.
Build and run tests
Add Run steps to run tests in Harness CI.
If you want to view test results in Harness, make sure your test commands produce reports in JUnit XML format and that your steps include the reports specification. The following example uses xcpretty to produce reports in JUnit XML format.
If you want to view test results in Harness, make sure your test commands produce reports in JUnit XML format and that your steps include the reports specification. The following example uses xcpretty to produce reports in JUnit XML format.
Specify version
Xcode is pre-installed on Harness Cloud machines. For details about all available tools and versions, go to Platforms and image specifications.
Use xcode-select in a Run step to switch between pre-installed versions of Xcode.
If your build infrastructure machines have multiple versions of Xcode installed, you can use xcode-select in a Run step to switch versions.
Deploy to the App Store
The following examples use Fastlane in a Continuous Integration setup to deploy an app to the Apple App Store. The environment variables in these examples use secrets and expressions to store and recall sensitive values, such as FASTLANE_PASSWORD=<+secrets.getValue('fastlanepassword')>.
To learn more about app distribution, go to the Apple Developer documentation on Distribution.
Full pipeline examples
The following pipeline examples install dependencies, cache dependencies, and build and test an Xcode project.
This pipeline uses Harness Cloud build infrastructure and Cache Intelligence.
If you copy this example, replace the placeholder values with appropriate values for your code repo connector, repository name, and other applicable values. Depending on your project and organization, you may also need to replace projectIdentifier and orgIdentifier.
This pipeline uses a self-managed VM build infrastructure and Save and Restore Cache from S3 steps.
If you copy this example, replace the placeholder values with appropriate values for your code repo connector, repository name, and other applicable values. Depending on your project and organization, you may also need to replace projectIdentifier and orgIdentifier.
Next steps
Now that you have created a pipeline that builds and tests an iOS/macOS app, you could:
Create triggers to automatically run your pipeline.
Add steps to build and upload artifacts.
Add a step to build and push an image to a Docker registry.
Last updated
Was this helpful?