# Upload builds and managed symbols from CI

Register a managed Release build from GitHub Actions or Azure Pipelines, verify symbol pairs, and separate uploads from channel publication.

Source: https://appportal.io/docs/guides/cli-ci-uploads

Build once, retain its matching symbols, and upload from a protected job. The examples below register
a **single-target managed Linux build** and its Release assembly/Portable PDB pair. They do not create an installable
Linux release. Replace the project path, app identity, and protected branch with your own values.

## Prepare the job

[Install and verify the CLI](https://appportal.io/docs/api/cli-install). Set `APPPORTAL_CLI_VERSION` to an exact version
published in your approved package source. The installation commands use your configured NuGet sources;
keep signature verification enabled and configure any feed authentication through your credential provider.

Create an app/environment-bound upload credential in **App settings → CI uploads** and store it as
`APPPORTAL_UPLOAD_KEY`. Map it only into the upload step. SDK client keys, MCP OAuth profiles, and
server API credentials have different authority and cannot substitute for it.

The sample build writes optimized Release output with external Portable PDBs to `./artifacts/managed`.
Use the same output for validation and upload; do not rebuild or mix symbols from another configuration.

## Choose the deployment

Set the protected CI variable `APPPORTAL_CI_UPLOAD_ORIGIN` once for validation and upload.
Use `https://upload.appportal.io` for Production or `https://upload.stage.appportal.io` for Stage.
The examples select the app environment `production`. Set `--environment` in both steps to the
environment bound to your upload credential.

## GitHub Actions

Append these steps to a Linux job after checkout. Define `APPPORTAL_CLI_VERSION` and
`APPPORTAL_CI_UPLOAD_ORIGIN` as repository or environment variables. Define
`APPPORTAL_UPLOAD_KEY` as a secret. Only the upload step receives it, on pushes to the protected
`master` branch.

```yaml
- uses: actions/setup-dotnet@v5
  with:
    dotnet-version: 10.0.x
- name: Build the managed app
  shell: bash
  run: >-
    dotnet build ./src/MyApp/MyApp.csproj --configuration Release
    --output ./artifacts/managed -p:DebugType=portable -p:DebugSymbols=true -p:Optimize=true
- name: Install the selected AppPortal CLI
  shell: bash
  env:
    APPPORTAL_CLI_VERSION: ${{ vars.APPPORTAL_CLI_VERSION }}
  run: |
    set -euo pipefail
    : "${APPPORTAL_CLI_VERSION:?Set an exact published CLI version}"
    dotnet tool install AppPortal.Cli --version "$APPPORTAL_CLI_VERSION" --tool-path "$RUNNER_TEMP/appportal"
- name: Validate without uploading
  shell: bash
  env:
    APPPORTAL_CI_UPLOAD_ORIGIN: ${{ vars.APPPORTAL_CI_UPLOAD_ORIGIN }}
  run: |
    set -euo pipefail
    : "${APPPORTAL_CI_UPLOAD_ORIGIN:?Set the deployment upload origin}"
    "$RUNNER_TEMP/appportal/appportal" build register ./artifacts/managed \
      --symbols ./artifacts/managed --platform linux --project-type dotnet \
      --bundle-id com.example.myapp --app-version 1.0.0 --build-number "$GITHUB_RUN_NUMBER" \
      --source-revision "$GITHUB_SHA" --server "$APPPORTAL_CI_UPLOAD_ORIGIN" --environment production \
      --managed-symbols --configuration Release --strict-symbols --dry-run --json
- name: Register the build and upload managed symbols
  if: github.event_name == 'push' && github.ref == 'refs/heads/master'
  shell: bash
  env:
    APPPORTAL_UPLOAD_KEY: ${{ secrets.APPPORTAL_UPLOAD_KEY }}
    APPPORTAL_CI_UPLOAD_ORIGIN: ${{ vars.APPPORTAL_CI_UPLOAD_ORIGIN }}
  run: |
    set -euo pipefail
    : "${APPPORTAL_UPLOAD_KEY:?Set the app-scoped upload secret}"
    : "${APPPORTAL_CI_UPLOAD_ORIGIN:?Set the deployment upload origin}"
    "$RUNNER_TEMP/appportal/appportal" build register ./artifacts/managed \
      --symbols ./artifacts/managed --platform linux --project-type dotnet \
      --bundle-id com.example.myapp --app-version 1.0.0 --build-number "$GITHUB_RUN_NUMBER" \
      --source-revision "$GITHUB_SHA" --server "$APPPORTAL_CI_UPLOAD_ORIGIN" --environment production \
      --managed-symbols --configuration Release --strict-symbols --json
```

Keep pull-request checks credential-free. Do not use `pull_request_target` to run untrusted pull-request
code with upload secrets. Protect the publishing branch and give the surrounding job only its required permissions.

## Azure Pipelines

Use a Linux agent after checkout. Define `APPPORTAL_CLI_VERSION` and
`APPPORTAL_CI_UPLOAD_ORIGIN` as pipeline variables. Define `APPPORTAL_UPLOAD_KEY` as a secret.

```yaml
- task: UseDotNet@2
  inputs:
    packageType: sdk
    version: 10.0.x
- bash: >-
    dotnet build ./src/MyApp/MyApp.csproj --configuration Release
    --output ./artifacts/managed -p:DebugType=portable -p:DebugSymbols=true -p:Optimize=true
  displayName: Build the managed app
- bash: |
    set -euo pipefail
    : "${APPPORTAL_CLI_VERSION:?Set an exact published CLI version}"
    if [[ "$APPPORTAL_CLI_VERSION" == '$('* ]]; then
      echo 'Set APPPORTAL_CLI_VERSION to an actual published version.' >&2
      exit 1
    fi
    dotnet tool install AppPortal.Cli --version "$APPPORTAL_CLI_VERSION" --tool-path "$AGENT_TEMPDIRECTORY/appportal"
  displayName: Install the selected AppPortal CLI
  env:
    APPPORTAL_CLI_VERSION: $(APPPORTAL_CLI_VERSION)
- bash: |
    set -euo pipefail
    : "${APPPORTAL_CI_UPLOAD_ORIGIN:?Set the deployment upload origin}"
    if [[ "$APPPORTAL_CI_UPLOAD_ORIGIN" == '$('* ]]; then
      echo 'Configure APPPORTAL_CI_UPLOAD_ORIGIN before running this step.' >&2
      exit 1
    fi
    "$AGENT_TEMPDIRECTORY/appportal/appportal" build register ./artifacts/managed \
      --symbols ./artifacts/managed --platform linux --project-type dotnet \
      --bundle-id com.example.myapp --app-version 1.0.0 --build-number "$BUILD_BUILDID" \
      --source-revision "$BUILD_SOURCEVERSION" --server "$APPPORTAL_CI_UPLOAD_ORIGIN" --environment production \
      --managed-symbols --configuration Release --strict-symbols --dry-run --json
  displayName: Validate without uploading
  env:
    APPPORTAL_CI_UPLOAD_ORIGIN: $(APPPORTAL_CI_UPLOAD_ORIGIN)
- bash: |
    set -euo pipefail
    : "${APPPORTAL_UPLOAD_KEY:?Set the app-scoped upload secret}"
    if [[ "$APPPORTAL_UPLOAD_KEY" == '$('* ]]; then
      echo 'Configure the APPPORTAL_UPLOAD_KEY secret before uploading.' >&2
      exit 1
    fi
    : "${APPPORTAL_CI_UPLOAD_ORIGIN:?Set the deployment upload origin}"
    if [[ "$APPPORTAL_CI_UPLOAD_ORIGIN" == '$('* ]]; then
      echo 'Configure APPPORTAL_CI_UPLOAD_ORIGIN before running this step.' >&2
      exit 1
    fi
    "$AGENT_TEMPDIRECTORY/appportal/appportal" build register ./artifacts/managed \
      --symbols ./artifacts/managed --platform linux --project-type dotnet \
      --bundle-id com.example.myapp --app-version 1.0.0 --build-number "$BUILD_BUILDID" \
      --source-revision "$BUILD_SOURCEVERSION" --server "$APPPORTAL_CI_UPLOAD_ORIGIN" --environment production \
      --managed-symbols --configuration Release --strict-symbols --json
  displayName: Register the build and upload managed symbols
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'), ne(variables['Build.Reason'], 'PullRequest'))
  env:
    APPPORTAL_UPLOAD_KEY: $(APPPORTAL_UPLOAD_KEY)
    APPPORTAL_CI_UPLOAD_ORIGIN: $(APPPORTAL_CI_UPLOAD_ORIGIN)
```

The guards reject empty variables and unresolved Azure macros before invoking the installer or upload
command, without printing their values. Keep them when adapting the example.

## Check the result and recover safely

`--dry-run` validates local inputs without upload or publication requests. It does not test deployment
connectivity or validate a remote service URL. It does not prove server
authorization, app signing, or crash-frame resolution. `--strict-symbols` rejects missing uploadable
symbols; the hosted managed profile also checks Release/optimized assembly and external Portable PDB inputs.

Read the JSON `managedSymbols` results. `pending-pair` means the matching assembly/PDB counterpart is
not yet verified; `pair-verified` means the uploaded artifact pair is verified. Neither status means every
crash frame resolves. Keep the exact build outputs and inspect the occurrence's separate **Symbols** and
**Processing** states. A rejection or missing managed verification metadata fails the command.

Keep nonzero exit codes visible. Do not use `continue-on-error`, disable signature checks, or replace a
failed upload with a success message. Resolve credential scope, build identity, symbol-pair, or service
availability errors before retrying. Identical managed artifact retries are safe; upload receipt status
is still separate from crash processing.

## Attach and publish an app artifact

For supported installable artifacts, `appportal build release` (or `appportal upload`) attaches an
IPA, APK, AAB, or Windows ZIP. Omit `--groups` to leave a draft. Registering a Linux build does not imply
Linux app-artifact distribution support.

### Publish to release channels from CI

Install the exact CLI version supplied through your approved package source that supports both the
dedicated Upload service and `build release --groups`. After installing it, run one of the steps below
with a signed APK and its matching symbols. Replace the paths and bundle ID, and use the version and
build number embedded in the APK. Set `APPPORTAL_RELEASE_CHANNELS` to the IDs of your existing channels
as a comma-separated list.

Give the protected step an `APPPORTAL_UPLOAD_KEY` for the app and environment and a separate
`APPPORTAL_SERVER_KEY` with only `ReleasePublish` for the same app and environment. Set
`APPPORTAL_CI_UPLOAD_ORIGIN` and `APPPORTAL_AUTOMATION_URL` from the same deployment. For Production
these are `https://upload.appportal.io` and `https://automation.appportal.io`.

#### GitHub Actions

```yaml
- name: Publish the Android release
  if: github.event_name == 'push' && github.ref == 'refs/heads/master'
  shell: bash
  env:
    APPPORTAL_UPLOAD_KEY: ${{ secrets.APPPORTAL_UPLOAD_KEY }}
    APPPORTAL_SERVER_KEY: ${{ secrets.APPPORTAL_SERVER_KEY }}
    APPPORTAL_CI_UPLOAD_ORIGIN: ${{ vars.APPPORTAL_CI_UPLOAD_ORIGIN }}
    APPPORTAL_AUTOMATION_URL: ${{ vars.APPPORTAL_AUTOMATION_URL }}
    APPPORTAL_RELEASE_CHANNELS: ${{ vars.APPPORTAL_RELEASE_CHANNELS }}
    APPPORTAL_APP_VERSION: ${{ vars.APPPORTAL_APP_VERSION }}
  run: |
    set -euo pipefail
    : "${APPPORTAL_UPLOAD_KEY:?Set the app-scoped upload secret}"
    : "${APPPORTAL_SERVER_KEY:?Set the ReleasePublish secret}"
    : "${APPPORTAL_CI_UPLOAD_ORIGIN:?Set the Upload origin}"
    : "${APPPORTAL_AUTOMATION_URL:?Set the Automation origin}"
    : "${APPPORTAL_RELEASE_CHANNELS:?Set the release channel IDs}"
    : "${APPPORTAL_APP_VERSION:?Set the APK version}"
    "$RUNNER_TEMP/appportal/appportal" build release ./artifacts/android \
      --artifact ./artifacts/android/app.apk --symbols ./artifacts/android/symbols \
      --platform android --project-type native --bundle-id com.example.myapp \
      --app-version "$APPPORTAL_APP_VERSION" --build-number "$GITHUB_RUN_NUMBER" \
      --server "$APPPORTAL_CI_UPLOAD_ORIGIN" --environment production --target release \
      --source-revision "$GITHUB_SHA" --idempotency-key "github-$GITHUB_RUN_ID" \
      --groups "$APPPORTAL_RELEASE_CHANNELS" --strict-symbols --json
```

#### Azure Pipelines

```yaml
- bash: |
    set -euo pipefail
    for name in APPPORTAL_UPLOAD_KEY APPPORTAL_SERVER_KEY APPPORTAL_CI_UPLOAD_ORIGIN \
      APPPORTAL_AUTOMATION_URL APPPORTAL_RELEASE_CHANNELS APPPORTAL_APP_VERSION; do
      value="${!name-}"
      if [[ -z "$value" || "$value" == '$('* ]]; then
        echo "Configure $name before publishing." >&2
        exit 1
      fi
    done
    "$AGENT_TEMPDIRECTORY/appportal/appportal" build release ./artifacts/android \
      --artifact ./artifacts/android/app.apk --symbols ./artifacts/android/symbols \
      --platform android --project-type native --bundle-id com.example.myapp \
      --app-version "$APPPORTAL_APP_VERSION" --build-number "$BUILD_BUILDID" \
      --server "$APPPORTAL_CI_UPLOAD_ORIGIN" --environment production --target release \
      --source-revision "$BUILD_SOURCEVERSION" --idempotency-key "azure-$BUILD_BUILDID" \
      --groups "$APPPORTAL_RELEASE_CHANNELS" --strict-symbols --json
  displayName: Publish the Android release
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'), ne(variables['Build.Reason'], 'PullRequest'))
  env:
    APPPORTAL_UPLOAD_KEY: $(APPPORTAL_UPLOAD_KEY)
    APPPORTAL_SERVER_KEY: $(APPPORTAL_SERVER_KEY)
    APPPORTAL_CI_UPLOAD_ORIGIN: $(APPPORTAL_CI_UPLOAD_ORIGIN)
    APPPORTAL_AUTOMATION_URL: $(APPPORTAL_AUTOMATION_URL)
    APPPORTAL_RELEASE_CHANNELS: $(APPPORTAL_RELEASE_CHANNELS)
    APPPORTAL_APP_VERSION: $(APPPORTAL_APP_VERSION)
```

The CLI uploads the artifact before publishing to channels. If a later channel fails, keep the JSON
result and verify which channels received the release before retrying with the same build outputs.
[Verify the release and its recipients](https://appportal.io/docs/guides/distribution#publish-through-the-cli).

Task references: [GitHub .NET setup](https://github.com/actions/setup-dotnet/tree/v5),
[Azure .NET setup](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/use-dotnet-v2?view=azure-pipelines),
and [Azure secret variables](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops#secret-variables).
