---
title: Auto-Increment Build Numbers
description: Learn how to automatically increment build numbers for your Android and iOS builds in Capawesome Cloud.
---

# Auto-Increment Build Numbers

Capawesome Cloud provides automatic build number incrementing through the `CI_BUILD_NUMBER` environment variable, which increments with each build.
This guide shows you how to automatically apply this build number to your native Android and iOS projects.

## Prerequisites

This guide assumes you have already set up Trapeze. If you haven't done this yet, follow the [Advanced: Trapeze](native-configurations.md#advanced-trapeze) section of the Native Configurations guide first to:

1. Install Trapeze
2. Set up the build script in your `package.json`

!!! info "App name and package name"

    Build numbers and version names need Trapeze. To change the app name or the package name (the application ID on Android, the bundle ID on iOS), you don't — use a [native configuration](native-configurations.md) instead.

## Configuration

Create a configuration file named `capawesome.yml` in the root of your project with the following content:

```yaml
vars:
  CI_BUILD_NUMBER:
    default: 1

platforms:
  android:
    versionCode: $CI_BUILD_NUMBER
  ios:
    buildNumber: $CI_BUILD_NUMBER
```

This configuration maps the `CI_BUILD_NUMBER` environment variable to the version code on Android and the build number on iOS.

???+ info "Default value"

    The default value of `1` is used for local development when the `CI_BUILD_NUMBER` environment variable is not set. In Capawesome Cloud, this variable is automatically provided and increments with each build.

## How It Works

When you trigger a build in Capawesome Cloud:

1. The `CI_BUILD_NUMBER` environment variable is automatically set to a sequential number
2. The [web build script](web-build-script.md) runs Trapeze with your configuration
3. Trapeze updates the native project files with the current build number
4. Your app is built with the incremented build number

This ensures each build has a unique, incrementing build number without manual intervention.

## Custom Starting Number

If you need to start incrementing from a specific number (for example, to continue from your current build number), you can set the next build number directly in the [app settings](https://console.cloud.capawesome.io/apps/_/settings){:target="_blank"}.
The next build number must be at least `1` higher than the previous build number, or `1` if no build has been created yet.

Alternatively, you can add an offset to the `CI_BUILD_NUMBER` variable in your build script:

```json
{
  "scripts": {
    "capawesome:build": "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER + 1000)); if [ \"$CI_PLATFORM\" = \"ios\" ] || [ \"$CI_PLATFORM\" = \"android\" ]; then npx trapeze run capawesome.yml -y --$CI_PLATFORM; fi && npm run build"
  }
}
```

Replace `1000` with your desired offset. For example, if your current build number is 150 and you want the next build to be 151, use an offset of 150.

## Version Name and Build Number

You can combine build number incrementing with version name management:

```yaml
vars:
  VERSION_NAME:
  CI_BUILD_NUMBER:
    default: 1

platforms:
  android:
    versionName: $VERSION_NAME
    versionCode: $CI_BUILD_NUMBER
  ios:
    version: $VERSION_NAME
    buildNumber: $CI_BUILD_NUMBER
```

Then set the `VERSION_NAME` variable in your Capawesome Cloud environment (e.g., `1.0.0`). This way:

- The version name (e.g., `1.0.0`) remains consistent across builds
- The build number increments automatically with each build
