Jan 16, 2023 - 5 min read

The next step after creating and signing a new app flavour was to ensure that the CI/CD pipeline functioned as intended. The initial problem I faced is outlined in this article. I had to make two flavours of the same app:
This article covers how I updated the CircleCI configuration to ensure the APK from the hub flavour was uploaded to a folder in Azure.
CircleCI is a continuous integration & delivery platform that helps development teams release code rapidly and automate the build, test, and deployment process. After repositories on GitHub or Bitbucket are authorized and added as a project to CircleCI, jobs can begin to run.
CircleCI finds and runs the .circleci/config.yml file, which orchestrates your build, tests, security scans, approval steps, and deployment.
The CI/CD pipeline builds the flavours of the app from the latest tag on the main branch. However, several changes needed to be made to the configuration due to the new flavour of the app.
One of the first steps was to create new environment variables for the project within CircleCI.
In CircleCI, I created two new environment variables:
For the hub flavour of the app, I created a new workflow in the circleci/config.yml file called build-hub. All of the workflows use the same job. Its called android-build. It’s an identical build for all the other app flavours. However, new logic had to be included. It was important to determine if the apk was from the hub flavour of the app as it required different functionality. To do this I inserted an “If” statement. This meant the keystore would be decrypted using the new environment variables I created above. All the other steps in the android-build job installs the related dependencies and Docker images. Below is a snippet from the android-build job where the new logic has been added.
run:name: Create release keystore.properties by overwriting the debug one that is stored in the repocommand: |if [[ $parameters.flavor == "hub" ]]; thenprintf "ORG_GRADLE_PROJECT_KEY_ALIAS=hubkeyORG_GRADLE_PROJECT_KEY_PASSWORD=$HUB_GRADLE_PROJECT_KEYSTORE_PASSORG_GRADLE_PROJECT_KEYSTORE_FILE=release-hg-keystoreORG_GRADLE_PROJECT_STORE_PASSWORD=$HUB_GRADLE_PROJECT_STORE_PASSWORD" > keystore.propertieselseprintf "ORG_GRADLE_PROJECT_KEY_ALIAS=upload_keyORG_GRADLE_PROJECT_KEY_PASSWORD=$HUB_GRADLE_PROJECT_KEYSTORE_PASSORG_GRADLE_PROJECT_KEYSTORE_FILE=release-bg-keystoreORG_GRADLE_PROJECT_STORE_PASSWORD=$HUB_GRADLE_PROJECT_STORE_PASSWORD" > keystore.propertiesfi
In the .circleci/config.yml file, I created a new workflow called build-hub for the hub flavour of the app.
The workflow used the android-build job, which is shared among all the flavours.
However, I added logic to ensure that if the APK was from the hub flavour, the keystore would be decrypted using the new environment variables.
jobs:android-build:steps:- run:name: Decrypt keystore for hub flavourcommand: |if [[ $CIRCLE_BRANCH == "hub" ]]; thengpg --quiet --batch --yes --decrypt --passphrase="$Hub_Encryption_Key" --output keystore.jks keystore.jks.gpgfi
In addition to the build-hub workflow, I created a new job called upload-apk-to-azure. This job does the following:
az loginaz account set --subscriptionjobs:upload-apk-to-azure:steps:- run:name: Upload APK to Azurecommand: |az login --service-principal -u "$AZURE_CLIENT_ID" -p "$AZURE_CLIENT_SECRET" --tenant "$AZURE_TENANT_ID"az account set --subscription "$AZURE_SUBSCRIPTION_ID"az storage copy -s ./build/outputs/apk/hub.apk -d "$AZURE_STORAGE_CONTAINER/app-apks/hub.apk"
After completing all these steps, I successfully created the new build-hub workflow. This workflow sends the latest version of the hub APK to Azure, allowing it to be downloaded by a physical hub via a QR code. This solution demonstrates how CI/CD can be effectively implemented in CircleCI, and how to update configurations to send build artifacts to Azure.