> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Bitrise

> 在 Bitrise 上运行 iOS 和 Android 测试，在同一流水线中为每个平台设置一个工作流。

export const setupPrompt = `添加一条 Bitrise 流水线，在 iOS 和 Android 上运行这个项目的 e2e 测试。文档：\`https://e2e.com/docs/ci/bitrise.md\` 和 \`https://e2e.com/docs/ci.md\`

1. 阅读这两个页面。
2. 将工作流添加到 \`bitrise.yml\`。根据这个项目调整项目路径、scheme、stack 和 Node 版本。
3. 提醒我在 Bitrise 工作流编辑器的 Secrets 中添加模型密钥。
4. 在我启动构建后，读取构建日志并修复错误，直到两个工作流都通过。`;

此配置遵循[移动端作业](https://e2e.com/docs/zh/ci#mobile-jobs)中的规则，在同一流水线中为每个平台运行一个工作流。

<SetupPrompt>

<Prompt description={setupPrompt} children={setupPrompt} actions={["copy", "cursor"]} />

</SetupPrompt>

## 工作流

Bitrise 步骤负责启动设备：macOS 上使用 `xcode-start-simulator`，Linux 上使用 `avd-manager` 和 `wait-for-android-emulator`。Android 工作流会在 Gradle 构建之前启动模拟器，让它在 APK 编译期间完成启动。发布版 APK 必须签名；React Native 和 Expo 模板使用调试密钥库为其签名。

```yaml title="bitrise.yml" expandable
format_version: '25'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

tools:
  nodejs: 24:latest

pipelines:
  e2e:
    triggers:
      push:
      - branch: main
      pull_request:
      - target_branch: main
    workflows:
      e2e-ios: {}
      e2e-android: {}

workflows:
  e2e-ios:
    meta:
      bitrise.io:
        stack: osx-xcode-26.6.x
    steps:
    - git-clone@8: {}
    - script@1:
        title: Install dependencies
        inputs:
        - content: |-
            #!/usr/bin/env bash
            set -euo pipefail
            npm ci
            cd ios && pod install
    - xcode-build-for-simulator@3:
        inputs:
        - project_path: ios/MyApp.xcworkspace
        - scheme: MyApp
        - configuration: Release
    - xcode-start-simulator@0:
        inputs:
        - destination: platform=iOS Simulator,name=iPhone 17,OS=26.5
    - script@1:
        title: Run e2e
        inputs:
        - content: |-
            #!/usr/bin/env bash
            set -euo pipefail
            xcrun simctl install booted "$BITRISE_APP_DIR_PATH"
            npx e2e run --target ios --reporter list,junit
    - script@1:
        title: Package the e2e output
        is_always_run: true
        inputs:
        - content: |-
            #!/usr/bin/env bash
            if [ -d .e2e ]; then (cd .e2e && zip -qr "$BITRISE_DEPLOY_DIR/e2e-ios.zip" .); fi
    - custom-test-results-export@1:
        inputs:
        - test_name: e2e-ios
        - base_path: $BITRISE_SOURCE_DIR/.e2e/junit.xml
        - search_pattern: '*'
    - deploy-to-bitrise-io@2: {}

  e2e-android:
    meta:
      bitrise.io:
        stack: ubuntu-noble-24.04-bitrise-2025-android
    steps:
    - git-clone@8: {}
    - script@1:
        title: Install dependencies
        inputs:
        - content: npm ci
    - avd-manager@2:
        inputs:
        - api_level: 35
        - tag: google_apis
        - abi: x86_64
    - android-build@1:
        inputs:
        - project_location: $BITRISE_SOURCE_DIR/android
        - module: app
        - variant: release
        - build_type: apk
    - wait-for-android-emulator@1: {}
    - script@1:
        title: Run e2e
        inputs:
        - content: |-
            #!/usr/bin/env bash
            set -euo pipefail
            adb install -r "$BITRISE_APK_PATH"
            npx e2e run --target android --reporter list,junit
    - script@1:
        title: Package the e2e output
        is_always_run: true
        inputs:
        - content: |-
            #!/usr/bin/env bash
            if [ -d .e2e ]; then (cd .e2e && zip -qr "$BITRISE_DEPLOY_DIR/e2e-android.zip" .); fi
    - custom-test-results-export@1:
        inputs:
        - test_name: e2e-android
        - base_path: $BITRISE_SOURCE_DIR/.e2e/junit.xml
        - search_pattern: '*'
    - deploy-to-bitrise-io@2: {}
```

## 产物和测试报告

`deploy-to-bitrise-io` 只上传 `$BITRISE_DEPLOY_DIR` 的顶层内容，因此每个工作流都会将 `.e2e/` 打包为 ZIP 文件放入该目录。`custom-test-results-export` 将 `junit.xml` 发送到 Test Reports 选项卡。即使某个步骤失败，这些步骤也会运行。

## 模型密钥

在应用工作流编辑器的 Secrets 中添加模型密钥。拉取请求（PR）构建只有在开启 **Expose for Pull Requests** 时才能获取该密钥，公开应用的构建则始终无法获取。没有密钥时，确定性测试仍会运行，但智能体判定和未录制的 `agent.act` 步骤会失败。参阅[模型凭据](https://e2e.com/docs/zh/ci#model-credentials)。

## 下一步

<CardGroup cols={2}>
  <Card title="持续集成" icon="rotate" href="/ci">
    CI 默认值、分片、重新运行和退出码。
  </Card>
  <Card title="托管设备" icon="cloud" href="/mobile#hosted-devices">
    从服务中租用设备，让运行器无需启动设备。
  </Card>
</CardGroup>
