# Upload and publish a test build

Inspect a mobile artifact, upload its build identity and symbols, publish it to a release channel, and verify an authorized download.

Source: https://appportal.io/docs/guides/distribution

AppPortal separates **uploading bytes** from **publishing a release**. An upload credential cannot
publish a release channel. Use a test artifact and test audience for this walkthrough.

## 1. Prepare the build and CLI

[Install the CLI](https://appportal.io/docs/api/cli-install). Build your app normally and retain the IPA, APK, or AAB,
its version/build number, and matching symbols for that build. Do not pair symbols from another build.
For .NET assembly/Portable PDB verification, follow the
[managed Release workflow](https://appportal.io/docs/api/cli-install#upload-managed-release-symbols).

From the project directory, inspect without uploading:

```bash
appportal build inspect . --json
```

Confirm the detected platform, bundle/application identity, version, and build number.
Correct detection with the documented CLI flags when needed.

## 2. Upload to the app environment

Create an environment-bound credential in **App settings → CI uploads**.
Store it as `APPPORTAL_UPLOAD_KEY` in CI. Choose the Upload origin for your deployment and
the app environment bound to your key. For a Production build:

```bash
appportal build release . \
  --artifact ./build/app-release.aab \
  --server https://upload.appportal.io --environment production
```

For Stage, use `https://upload.stage.appportal.io`. [Check the deployment and app environment](https://appportal.io/docs/api/cli-install#select-the-deployment-and-app-environment).

Without `--groups`, `build release` registers and uploads the artifact as a draft.
Save the artifact identifier returned by the CLI. Use `build register` when you only need build
identity and symbols. Use `--strict-symbols` if your pipeline must fail when required symbols are absent.

## 3. Publish through the authorized channel

Use an Automation credential with `ReleasePublish` for the same app and environment.
The [Automation contract](https://appportal.io/docs/api/automation-openapi.json) defines
POST `/v1/automation/releases/{artifactId}/publish`, its request body, and required
`Idempotency-Key`. Select an existing release channel you are authorized to publish to.

Save this as `publish.json`, replacing the channel ID:

```json
{ "channelId": "<test-channel-id>" }
```

Load the server credential from your CI secret store and choose a unique operation ID:

```bash
curl --fail-with-body \
  --request POST \
  --header "X-AppPortal-Server-Key: $APPPORTAL_SERVER_KEY" \
  --header "Idempotency-Key: $APPPORTAL_OPERATION_ID" \
  --header "Content-Type: application/json" \
  --data @publish.json \
  "$APPPORTAL_AUTOMATION_URL/v1/automation/releases/$APPPORTAL_ARTIFACT_ID/publish"
```

Set `APPPORTAL_AUTOMATION_URL` to your deployment’s Automation service; the production origin is
`https://automation.appportal.io`. Keep it on the same deployment as the upload service and credentials.
A successful publish returns HTTP 200;
verify the channel's resulting release before starting another operation.

Uploading a new artifact and publishing it are separate decisions. Confirm the artifact, channel,
audience, and optional notification before making the publish request.
A repeated request must retain the same idempotency key only when it represents the same operation.

### Publish through the CLI

To publish a signed artifact to existing channels in Production:

```bash
export APPPORTAL_UPLOAD_URL=https://upload.appportal.io
export APPPORTAL_AUTOMATION_URL=https://automation.appportal.io
appportal build release ./artifacts/app.apk \
  --environment production --groups chn_qa,chn_beta --json
```

Create channels and manage recipients in the portal's **Distribution groups** drawer, then replace
the sample group IDs with those existing channels. The CLI does not create channels or edit membership. Map
`APPPORTAL_UPLOAD_KEY` and a separate `APPPORTAL_SERVER_KEY` with `ReleasePublish` into the protected
step. The CLI uploads first, then publishes each group through Automation. `--group` and `-g` are
aliases for `--groups`. Omit groups to leave a draft; `--dry-run` sends no upload or publish requests.

Publication uses an idempotency key per artifact/group. If a later group fails, the command exits
unsuccessfully and reports the artifact and groups already completed. Preserve that JSON result and
reconcile the portal state before retrying; do not treat partial publication as an all-or-nothing rollback.
Signing and platform eligibility still apply. Windows ZIP inspection does not verify Authenticode,
and Windows group publication is blocked without authoritative signing verification.

For protected branch conditions and step-local secrets, use the
[GitHub Actions and Azure Pipelines examples](https://appportal.io/docs/guides/cli-ci-uploads).

## 4. Verify as the intended recipient

Open the [Downloads surface](https://download.appportal.io) as an authorized test recipient.
Confirm the expected app, version, build, and channel, then request a download.
Signed download URLs expire; share the authorized download entry point rather than treating an
expiring artifact URL as a permanent public link.

**Success:** the intended recipient can download the correct artifact, unauthorized access is
rejected, and the scope-filtered audit records the action. Also send telemetry from that exact build
and check its release attribution.

For failures, distinguish artifact/signing validation, credential scope, missing symbols,
channel-publication permission, and recipient download access. App-store installation restrictions
still apply to signed Apple/Android artifacts.
