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.
- Configure Bitrise project.
- Adding Bitrise build number to your Android app build.gradle. Add BITRISE_BUILD_NUMBER to your app build.gradle. Copy and paste code snippet:
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.