Adding Bitrise build number to Android app version Code

The tutorial shows how to pass Bitrise environment variables as arguments to build.gradle. This is part of a series of tutorials for building Android Continuous Integration and Continuous Delivery (CI/CD) with Bitrise.

Every time we publish an App release, each the build number needs to increment, for tracking purposes and also is required by the Google Play Store. Instead of manually updating versionCode for each release, we can use the Bitrise environment variable BITRISE_BUILD_NUMBER.

  1. Configure Bitrise project.
android {defaultConfig{...
Integer buildNumb = System.getenv("BITRISE_BUILD_NUMBER") as Integer
versionCode buildNumb ?: 1
versionName "1.6" + buildNumb
}
...
}

3. Push code to Github and trigger a new Bitrise build.

Bitrise build number is an environment variable by default, you can edit Build number in the Settings tab shown below.

4. Install the app on device, and now your App version is the Bitrise build number.

Test locally passing an environment variable to App build.gradle

“BITRISE_BUILD_NUMBER” to Gradle, run command in a terminal:

$BITRISE_BUILD_NUMBER=63 ./gradlew publishReleaseBundle

The app shows versionCode is 63.

Thanks for reading! Let me know if you have any questions.

Andres

software engineer, read, swim, travel. apps: https://goo.gl/rDuuQw https://goo.gl/15GvfE

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store