Output VersionName from Version Catalog (libs.versions.toml)

We have a slack message at the end of the build that uses $ANDROID_VERSION_NAME which works great if we override the version with an ENV variable using Change Android versionCode and versionName step (which we do for a release build).

We’ve started using the newer version catalog (libs.versions.toml) to set all of our versions including versionName for daily builds. For our daily build workflow we don’t override the versionName only the versionNumber (with $BITRISE_BUILD_NUMBER). Before moving to the Version Catalog, the versionName was hardoded in the build.gradle - which worked fine - $ANDROID_VERSION_NAME read it correctly from the build.gradle if we didn’t override it)

The problem is that for this daily build, now that we have a non-hardcoded value in the build.gradle, bitrise sets $ANDROID_VERSION_NAME to libs.versions.versionName.get() which breaks our slack message if we try to use that variable for daily builds (no longer gives the real versionName - just that code above)

What I’d like to do is get the value either from the finished build, or read it from libs.versions.toml so that I can output it in the slack message for daily builds.


versionName = "2.82" 


android {
    defaultConfig {
        versionName libs.versions.versionName.get()

What step can I add (or code can I add into the android build) to get this value from either the libs.versions.toml file or from the built APK into an ENV variable that I can use for the slack message?

Probably the easiest is if you use a tool similar to jq, which can be used for printing values from structured files (JSON in case of jq).

I did a quick search and GitHub - mikefarah/yq: yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor seems to do that, and supports TOML - but I never used it before.

I don’t think there’s any step in the steplib which supports this out-of-the-box, so the suggestion would be to use a Script step, use yq to get the value, and then set the $ANDROID_VERSION_NAME env var using envman (Environment Variables - Bitrise Docs).

One of our test engineers created a workaround for us, custom script step - leaving it here for anyone that runs into this issue - it basically grabs the version from toml and writes it into the gradle file so that the Bitrise’s standard Change Android versionCode and versionNames step will pick it up (and can still override if needed). This allows our built to work correctly locally and allows to still function as it did with a hardcode:

#!/usr/bin/env bash
# fail if any commands fails
set -e
# make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully
set -o pipefail
# debug log
set -x

# The step after which updates the version code and sets the desired environment variables does not support dynamic versioning from the toml file. This scripts hard codes the version value in the gradle.build file.
while IFS= read -r line
  if [[ $line == *"versionName"* ]]; then
    SUBSTRING=`echo $line | cut -d'"' -f 2`
    sed -i "s/versionName libs.versions.versionName.get()/versionName \"$SUBSTRING\"/g" /bitrise/src/app/build.gradle
done < "$input"