Building a native iOS app
How to build an iOS app with codemagic.yaml
Setting up an iOS project
The apps you have available on Codemagic are listed on the Applications page. Click Add application to add a new app.
- On the Applications page, click Set up build next to the app you want to start building.
- On the popup, select iOS App as the project type and click Continue.
- Create a
codemagic.yamlfile and add in it the commands to build, test and publish your project. See the full iOS workflow example below.
- Commit the configuration file to the root of your repository.
- Back in app settings in Codemagic, scan for the
codemagic.yamlfile by selecting a branch to scan and clicking the Check for configuration file button at the top of the page. Note that you can have different configuration files in different branches.
- If a
codemagic.yamlfile is found in that branch, you can click Start your first build and select the branch and workflow to build.
- Finally, click Start new build to build the app.
Note that you need to set up a webhook for automatic build triggering. Click the Create webhook button on the right sidebar in app settings to add a webhook (not available for apps added via SSH/HTTP/HTTPS).
Building an unsigned native iOS app (.app)
For building an unsigned iOS app (.app), you need to run the following command in the scripts section:
- xcodebuild build -workspace "MyXcodeWorkspace.xcworkspace" -scheme "MyScheme" CODE_SIGN_INDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
If you don’t have a workspace, use
-project "MyXcodeProject.xcodeproj" instead of the
-workspace "MyXcodeWorkspace.xcworkspace" option.
Your artifact will be generated at the default Xcode path. You can access it by adding the following pattern in the
artifacts section of
If you have Xcode Debugging Symbols enabled, the dSYM file will be generated in the same directory as the app and can be accessed with the following artifact pattern:
Building a native iOS app archive (.ipa)
For building an archived iOS app (.ipa) from your Xcode project, you need to run the following command in the scripts section:
- xcode-project build-ipa --project "MyXcodeProject.xcodeproj" --scheme "MyScheme"
You can also build an archive from your Xcode workspace:
- xcode-project build-ipa --workspace "MyXcodeWorkspace.xcworkspace" --scheme "MyScheme"
Please check Codemagic CLI tools documentation to learn about more optional arguments to
By default, your artifacts will be generated into
build/ios/ipa but you can specify a different location using the
--ipa-directory option. The Xcode build log can be made available with the
/tmp/xcodebuild_logs/*.log pattern and the dSYM file will be still available at the default Xcode path.
artifacts: - build/ios/ipa/*.ipa - /tmp/xcodebuild_logs/*.log - $HOME/Library/Developer/Xcode/DerivedData/**/Build/**/*.dSYM
Testing, code signing and publishing an iOS app
To test, code sign and publish an iOS app:
- The code for testing an iOS app also goes under
scripts, before build commands. An example for testing an iOS app can be found here.
- All iOS applications need to be signed before release. A full example of iOS code singing with YAML is available here.
- All generated artifacts can be published to external services. The available integrations currently are email, Slack and App Store Connect. It is also possible to publish elsewhere with custom scripts (e.g. Firebase App Distribution). Script examples for all of them are available here.
iOS workflow example
The following example shows a workflow that can be used to publish your iOS app to App Store Connect.
workflows: ios-workflow: name: ios_workflow environment: groups: - app_store_credentials # <-- (Includes APP_STORE_CONNECT_ISSUER_ID, APP_STORE_CONNECT_KEY_IDENTIFIER, APP_STORE_CONNECT_PRIVATE_KEY) - certificate_credentials # <-- (Includes CERTIFICATE_PRIVATE_KEY) - other # Add the group environment variables in Codemagic UI (either in Application/Team variables) - https://docs.codemagic.io/variables/environment-variable-groups/ vars: XCODE_WORKSPACE: "YOUR_WORKSPACE_NAME.xcworkspace" # PUT YOUR WORKSPACE NAME HERE XCODE_SCHEME: "YOUR_SCHEME_NAME" # PUT THE NAME OF YOUR SCHEME HERE xcode: latest cocoapods: default triggering: events: - push branch_patterns: - pattern: master include: true source: true scripts: - name: Set up keychain to be used for code signing using Codemagic CLI 'keychain' command script: | keychain initialize - name: Fetch signing files script: | app-store-connect fetch-signing-files $(xcode-project detect-bundle-id) --type IOS_APP_STORE --create - name: Add certificates to keychain script: | keychain add-certificates - name: Increment build number script: agvtool new-version -all $(($BUILD_NUMBER +1)) - name: Set up code signing settings on Xcode project script: xcode-project use-profiles - name: Build ipa for distribution script: xcode-project build-ipa --workspace "$XCODE_WORKSPACE" --scheme "$XCODE_SCHEME" artifacts: - build/ios/ipa/*.ipa - /tmp/xcodebuild_logs/*.log - $HOME/Library/Developer/Xcode/DerivedData/**/Build/**/*.dSYM publishing: app_store_connect: api_key: $APP_STORE_CONNECT_PRIVATE_KEY # Contents of the API key key_id: $APP_STORE_CONNECT_KEY_IDENTIFIER # Alphanumeric value that identifies the API key issuer_id: $APP_STORE_CONNECT_ISSUER_ID # Alphanumeric value that identifies who created the API key submit_to_testflight: false # Optional boolean, defaults to false. Whether or not to submit the uploaded build to TestFlight to automatically enroll your build to beta testers. # beta_groups: # Specify the names of beta tester groups that will get access to the build once it has passed beta review. # - group name 1 # - group name 2