# Build Distribution | Sentry for iOS

This feature is available only if you're in the [Early Adopter program](https://docs.sentry.io/organization/early-adopter-features.md). Features available to Early Adopters are still in-progress and may have bugs. We recognize the irony.

[Build Distribution](https://docs.sentry.io/product/build-distribution.md) helps you securely distribute iOS builds to your internal teams and beta testers. Streamline your distribution workflow with automated uploads from CI.

## [Getting Started](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution.md#getting-started)

**Accepted Formats**: XCArchive

**Upload Mechanisms**: [Fastlane Plugin](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution.md#uploading-with-fastlane) (version 1.35.0 or higher) *or* [Sentry CLI](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution.md#uploading-with-the-sentry-cli)

### [Uploading With Fastlane](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution.md#uploading-with-fastlane)

The Fastlane plugin can be used to upload XCArchive or IPA builds to Sentry. On GitHub Actions, Fastlane will automatically detect your [build's metadata](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution.md#upload-metadata) and include it in the upload. In other Continuous Integration (CI) environments, you may need to manually set metadata values.

1. Configure the [Sentry Fastlane plugin](https://docs.sentry.io/platforms/apple/guides/ios/dsym.md#sentry-fastlane-plugin) (version `1.36.0`):

   ```ruby
   bundle exec fastlane add_plugin fastlane-plugin-sentry
   ```

2. Set up `SENTRY_AUTH_TOKEN` in your environment (you can generate a token [here](https://sentry.sentry.io/settings/auth-tokens/))

3. In `FastFile`, add a call to `sentry_upload_build` after your build step:

   `Fastfile`

   ```ruby
   lane :upload_to_sentry do
      build_ios_app(
        scheme: 'YourScheme',
        configuration: 'Release',
      )
      sentry_upload_build(
        org_slug: 'your-org',
        project_slug: 'your-project',
        build_configuration: 'Release' # Adjust to your configuration
      )
   end
   ```

4. After an upload has successfully processed, confirm the metadata is correct in the Sentry UI

The Fastlane plugin automatically detects all build metadata. If needed, the metadata values can be overridden by passing parameters to `sentry_upload_build`:

`Fastfile`

```ruby
lane :upload_to_sentry do
  build_ios_app(
    scheme: 'YourScheme',
    configuration: 'Release',
  )
  sentry_upload_build(
    org_slug: 'your-org',
    project_slug: 'your-project',
    build_configuration: 'Release',
    # Optional metadata overrides:
    head_sha: 'abc123',
    base_sha: 'def456',
    vcs_provider: 'github',
    head_repo_name: 'organization/repository',
    base_repo_name: 'organization/repository',
    head_ref: 'feature-branch',
    base_ref: 'main',
    pr_number: '42'
  )
end
```

See the [Fastlane repo](https://github.com/getsentry/sentry-fastlane-plugin) for more information.

### [Uploading with the Sentry CLI](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution.md#uploading-with-the-sentry-cli)

1. Install the [sentry-cli](https://docs.sentry.io/cli.md) (version `3.1.0`)

   We recommend using the latest version for the best possible experience, but at a minimum version `2.58.2` is required.

2. Authenticate the Sentry CLI by [following these steps](https://docs.sentry.io/cli/configuration.md#to-authenticate-manually)

3. Build your app to create an XCArchive (preferred) or IPA

4. Invoke the following CLI command to trigger the upload:

   ```bash
   sentry-cli build upload app.xcarchive \
     --org your-org \
     --project your-project \
     --build-configuration Release
   ```

5. After an upload has successfully processed, confirm the metadata is correct in the Sentry UI

## [Downloading Builds](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution.md#downloading-builds)

Once builds are uploaded to Sentry, your team members and beta testers can download them through the Sentry web interface.

1. Open the URL printed to the console after uploading the build
2. Click the **Install** button on the right side of the page

3) Either scan the QR code from a mobile device or click the **Download** button to download the build directly

After downloading, you can install the build directly on your iOS device. For more information on installing enterprise apps, see [Apple's documentation on installing custom apps](https://support.apple.com/en-us/118254).

## [Upload Metadata](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution.md#upload-metadata)

We use build metadata to organize builds in the UI and ensure correct comparisons.

| Field                   | Description                                                                                               |
| ----------------------- | --------------------------------------------------------------------------------------------------------- |
| `org`\*                 | Sentry organization slug                                                                                  |
| `project`\*             | Sentry project slug                                                                                       |
| `build-configuration`\* | Build configuration describing how the app was built, for example `Release` or `Debug` or `Release-Bazel` |
| `head-sha`              | Current commit SHA                                                                                        |
| `base-sha`              | Base commit SHA (for comparisons, recommended to use the branch's merge-base)                             |
| `head-repo-name`        | Repository name (`org/repo`)                                                                              |
| `pr-number`             | Pull request number                                                                                       |
| `head-ref`              | Branch or tag name                                                                                        |
| `base-ref`              | Base branch name                                                                                          |

\* *required field*

### [Build Configuration](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution.md#build-configuration)

Features such as automatically comparing the head build against the base build **will only compare builds of the same build configuration**. This is important to consider when setting up Size Analysis in your CI. For example, `Release` and `Debug` builds can be drastically different depending on the compiler and linker settings used during the build process. Trying to compare the two would give unexpected results.

Sometimes this is expected though, say you want to test the impact of converting your project to use Bazel (e.g. `Release` vs `Release-Bazel`). In this case, it's still possible to perform a manual comparison of builds with different build configurations.

* #### [Auto-Update SDK](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution/auto-update.md)

  Enable automatic update checks and installations for internal iOS builds using the Sentry Auto-Update SDK.

## Pages in this section

- [auto-update](https://docs.sentry.io/platforms/apple/guides/ios/build-distribution/auto-update.md)
