Skip to content

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 for native configurations. If you haven't done this yet, follow the Overwrite Native Configurations guide first to:

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

Configuration

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

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.

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 capawesome:build script 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 modify the build script:

{
  "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:

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