Skip to content
Latchkey

How to Increment the Build Number in CI

Stores reject a build whose number is not higher than the last upload, so derive it from GITHUB_RUN_NUMBER or bump it with fastlane.

Tie the build number to github.run_number for a monotonic value, or use fastlane's increment_build_number. iOS uses CFBundleVersion; Android uses versionCode.

Steps

  • Use ${{ github.run_number }} as a monotonic build number.
  • iOS: set CFBundleVersion via agvtool or increment_build_number.
  • Android: pass the value into versionCode via a Gradle property.

Fastfile

Fastfile
lane :bump do
  increment_build_number(
    build_number: ENV["GITHUB_RUN_NUMBER"],
    xcodeproj: "MyApp.xcodeproj"
  )
end

Gotchas

  • The build number only needs to increase; the marketing version (CFBundleShortVersionString) is separate.
  • For Android, read the value in Gradle: versionCode System.getenv("GITHUB_RUN_NUMBER").toInteger().

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →