# Circle CI

Source: https://help.testapp.io/circle-ci/

Circle CI pipeline allows you to build and upload both Android & iOS apps to TestApp.io to notify your testers for testing and feedback.

## Configuration

| Key | Description | Env Var(s) | Default |
| --- | --- | --- | --- |
| api_token | You can get it from [https://portal.testapp.io/profile/tokens](https://portal.testapp.io/profile/tokens) | TESTAPPIO_API_TOKEN |  |
| app_id | You can get it from your app page at [https://portal.testapp.io/apps](https://portal.testapp.io/apps) | TESTAPPIO_APP_ID |  |
| release | It can be either both or Android or iOS | TESTAPPIO_RELEASE |  |
| apk | Path to the Android APK file | TESTAPPIO_ANDROID_PATH |  |
| ipa | Path to the iOS IPA file | TESTAPPIO_IOS_PATH |  |
| release_notes | Manually add the release notes to be displayed for the testers | TESTAPPIO_RELEASE_NOTES |  |
| git_release_notes | Collect release notes from the latest git commit message to be displayed for the testers: true or false | TESTAPPIO_GIT_RELEASE_NOTES | true |
| git_commit_id | Include the last commit ID in the release notes (works with both release notes options): true or false | TESTAPPIO_GIT_COMMIT_ID | false |
| notify | Send notifications to your team members about this release: true or false | TESTAPPIO_NOTIFY | false |

*Check* [*TA-CLI*](https://help.testapp.io/ta-cli/) *for more info*

---

### Setup Circle CI project

Add two project environment variables:

*Project Settings* → *Environment Variables* → *Add Environment Variable*

```
TESTAPPIO_API_TOKEN=
TESTAPPIO_APP_ID=
```

These values can be found in the portal: the API token at [Profile → API Tokens](https://portal.testapp.io/profile/tokens), and the App ID under [App → Integrations → Releases](https://portal.testapp.io/apps)

---

## iOS

Circle CI provides macOS executors for CI/CD pipelines and has [Fastlane](https://help.testapp.io/setup-ios-project-for-fastlane/) installed already, which means you don't need to install Fastlane in your pipeline.

### Using Fastlane (Build & Upload)

If you haven't yet, set up Fastlane and add the TestApp.io plugin.

[**Setup Fastlane →**](https://help.testapp.io/fastlane-plugin/)

```shell
fastlane add_plugin testappio
```

In Circle CI's `config.yml`, add `bundle install`, e.g.

```yaml
# ...
    steps:
      # ...
      - run: bundle install
      - run: bundle exec fastlane adhoc --verbose
# ...
```

Make sure that the codesign is configured to "manual" or the `gym` step of the Circle CI pipeline would fail with the error "no provisioning profile found".

Circle CI will build your project and upload your IPA file to TestApp.io for distribution.

### Without Fastlane

```yaml
version: 2.1

orbs:
  ios: circleci/ios@1.0.0

jobs:
  build-and-upload-ios:
    macos:
      xcode: "15.4" # Specify the Xcode version you need
    environment:
      release_notes: ""
      git_release_notes: true
      git_commit_id: false
      notify: true
    steps:
      - checkout

      # Build and archive the iOS app
      - run:
          name: Archive iOS app
          command: |
            xcodebuild -workspace YourWorkspace.xcworkspace -scheme YourScheme -sdk iphoneos -configuration Release archive -archivePath build/YourApp.xcarchive

      - run:
          name: Export IPA
          command: |
            xcodebuild -exportArchive -archivePath build/YourApp.xcarchive -exportPath build/ -exportOptionsPlist ExportOptions.plist

      # Upload to TestApp.io
      - run:
          name: Upload to TestApp.io
          command: |
            export INSTALL_DIR=/tmp
            curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
            $INSTALL_DIR/ta-cli publish --api_token=$TESTAPPIO_API_TOKEN --app_id=$TESTAPPIO_APP_ID --release="ios" --ipa=./build/YourApp.ipa --release_notes=$release_notes --notify=$notify --git_release_notes=$git_release_notes --git_commit_id=$git_commit_id --source="Circle CI"

workflows:
  default:
    jobs:
      - build-and-upload-ios
```

---

## Android

### Using Fastlane (Build & Upload)

If you haven't yet, set up Fastlane and add the TestApp.io plugin.

[**Setup Fastlane →**](https://help.testapp.io/fastlane-plugin/)

```shell
fastlane add_plugin testappio
```

In Circle CI's `config.yml`:

```yaml
# ...
    steps:
      # ...
      - run: bundle install
      - run: bundle exec fastlane android beta --verbose
# ...
```

### Without Fastlane

Create `.circleci/config.yml` file under your project directory and copy the below snippet.

```yaml
version: 2.1

orbs:
  android: circleci/android@1.0.3

jobs:
  build-and-upload:
    executor:
      name: android/android-machine
    environment:
      release_notes: ""
      git_release_notes: true
      git_commit_id: false
      notify: true
    steps:
      - checkout

      # For a debug build:
      - run:
          name: Assemble debug build
          command: |
            ./gradlew assembleDebug

      # For a release build:
      # - run:
      #     name: Assemble release build
      #     command: |
      #       ./gradlew assembleRelease

      - run:
          name: Upload to TestApp.io
          command: |
            export INSTALL_DIR=/tmp
            curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
            $INSTALL_DIR/ta-cli publish --api_token=$TESTAPPIO_API_TOKEN --app_id=$TESTAPPIO_APP_ID --release="android" --apk=./app/build/outputs/apk/debug/app-debug.apk --release_notes=$release_notes --notify=$notify --git_release_notes=$git_release_notes --git_commit_id=$git_commit_id --source="Circle CI"

workflows:
  default:
    jobs:
      - build-and-upload
```

If you already have the `.circleci/config.yml` file, you could copy the `build-and-upload` job to your pipeline.

> **Tip:** Once your CI/CD pipeline uploads a build, team members using the [TestApp.io mobile app](https://help.testapp.io/mobile-app-getting-started/) receive a push notification and can install the build with a single tap. You can also create [share links](https://help.testapp.io/how-to-share/) to distribute builds to external testers and clients.

---

Need help? [Contact us](https://testapp.io/contact-us/). we're happy to assist!
