How can I get version name in circle.yml with Android?

How can I get version name in circle.yml with Android?
I have to get version name to publish github release.

Hi there,

Welcome to our community!

I am not quite sure what you mean by version name. Could you please clarify?

Hi, thanks for your reply.

In build.gradle has versionName. I want to get verionName in config.yml of CircleCI.

You could read the config.yml file with a YAML parser. There are sure to be console tools and language libraries available. I use PHP, so when I need to parse YAML, I use Symfony/YAML.

I would put the versionName in an env var like this:

version: 2.1
      - checkout
      - run: ./gradlew test

and then read the value it in build.grade using something like System.getenv("ANDROID_VERSION_NAME") when you need to use it.


1 Like

I think the question is intended to extract the version number and the build number from the Gradle script and import this value to the circleci env and not vise-versa as you point here, this is very useful when you rename the output .apk with the version number in Gradle like this:

android.applicationVariants.all { variant ->
    variant.outputs.all {
      outputFileName = "${}-${variant.versionName}.apk"

in order to retrieve those variables from the Gradle and import them on the circleci building, and use these values to upload the correct artifact because the name is not going to be different for each new version or build.

      - store_artifacts:
          path: companyname/app/build/outputs/apk/companyname/debug/companynameDebug-7.9.5.apk

this is just because is not possible to use wildcards on the path and use something simple like this:

          path: companyname/app/build/outputs/apk/companyname/debug/*.apk

Iā€™m wondering if this is possible.

Everyone here did not answer the question. I have the same issue I need to extract the versionName used in the Android build gradle and set it to a CircleCI variable, which in turn I can use it inside a bash script. Please only answer if you know android gradle and have intelligent input