Android CI/CD using Azure DevOps-I

Anil Sisodiya
6 min readSep 26, 2020

Now a days CI/CD is integral part of any kind of software development. In this series I am going to explain, how we can use Azure DevOps for creating CI (continuous integration) and CD (continuous development) for Android projects. This series will be have two parts:-

Part 1: Continuous integration using Azure DevOps.

Part 2: Continuous delivery using Azure DevOps.

This is part 1.

Prerequisite : You should have Azure devOps account with Android project and Azure devOps Repository which contains android project code. You should also have all the required permission to create pipeline using your Android project repository.

Now let’s get started:-

Step 1: Login in Azure DevOps using Azure DevOps credentials. Once you login you will see projects on which you have access. click on project on which you want to create pipeline. When you click on project you will see screen as shown below. Now to see/create pipelines click on “Pipelines” option(with blue rocket icon) in left pane. It will open drop down in left pane below the “Pipelines” option. click on “Pipelines” options present in drop down as shown with red arrow in screen shot. It will list all the pipelines in right pane with the option “New pipeline” (indicated with red arrow in below screenshot) to create new pipeline. Click on “New pipeline” option.

Step 2: When you click on New pipeline option you will see screen shown as below. In this step you have to select code repository location. My code repository was present on “Azure Repos Git”, so I selected “Azure Repos Git” option as shown in below screenshot.

The interface which shown above is the new Interface provided by Azure DevOps , but if you want to use classic editor then you can click on “Use the classic editor” option as shown in below screenshot.

When you click on “Use the classic editor” option you will see interface shown in below screenshot. I used latest interface while creating pipeline, So I will continue with that and all subsequent steps are executed using newer Interface.

Step 3: When I click “Azure Repos Git” option. I could see all my code repository hosted using “Azure Repos Git”. Select the repository using which you wanted to create pipeline.

Step 4: Once you select code repository you will see various option to configure your pipeline. Select the option shown with arrow in below screenshot.

Step 5 : You will see initial YAML file as shown in below screenshot. Here we are going to add steps in YAML file with the help of “Show Assistant” option , which are required to create Android build.

Steps 6 : We need to sign android builds(apk), so that we can install it on device or upload on Google Play Store. For signing we required Keystore file, Keystore Password, Key alias, Key Password and we need to store them on secure place on Azure DevOps. This step explain how we can store Keystore Password, Key alias, Key Password in Azure DevOps securely. Click on “Library” option as shown in below screenshot with arrow 1. When you click on “Variable groups” option in right pane you will see list of variable groups in right pane as shown with arrow 2 in below screenshot. Click on “+ Variable Group” option as shown in below screenshot with arrow 3 to create new variable group.

Step 7: You will see screen shown in below screenshot. Add Keystore Password, Key alias, Key Password variable with their values using “+ Add” option (indicated by arrow in below screenshot) in this group with security option on. We will give appropriate name to this group, so that we can refer this variable group in pipeline. No pipeline can read values of this group variables, until we give permission to that pipeline.

Step 8 : In this step we will store keystore file on Azure devOps securely. Click on “Library” option present in left pane and then select “Secure files” option as shown in below screenshot with arrow 1. This will list down all the secure files. Now to add our keystore file as secure file click on “+ Secure file” option as shown in below screenshot with arrow 2. Upload your keystore file and you are good to go.

Step 9 : Now we have to go back to screen, which I mentioned in step 5 and then we have to add tasks Gradle@2 , AndroidSigning@3, PublishBuildArtifacts@1 with the help of assistant in steps section of YAML file.

Below screenshot shows how a task parameter’s can be configured using assistant and then “Add” button can be used to add that task in YAML file. You can also open assistant by clicking on “Settings” text present with each task in YAML file with pre-populated parameter values.

Step 10 : Your final YAML file look like as below. Replace the variables present in angular bracket with your project specific values to make it workable.

trigger: #specify branches on which you want to trigger CI

- master

- develop

pool:

vmImage: ‘macos-latest’

variables:

- group: <variables group name for key-alias, keystore password, key-password>

steps:

- task: Gradle@2

inputs:

workingDirectory: ‘’

gradleWrapperFile: ‘gradlew’

gradleOptions: ‘-Xmx3072m’

publishJUnitResults: false

tasks: ‘assemble<variantname>’

- task: AndroidSigning@3

inputs:

apkFiles: ‘**/*.apk’

apksignerKeystoreFile: ‘<key store file>’

apksignerKeystorePassword: ‘$(<key store password variable name>)’

apksignerKeystoreAlias: ‘$(<key store alias name>)’

apksignerKeyPassword: ‘$(<key password>)’

zipalign: false

- task: PublishBuildArtifacts@1

inputs:

PathtoPublish: ‘app/build/outputs/<path to apk>’

ArtifactName: ‘<project name>’

publishLocation: ‘Container’

Step 11: Now you should click on Save and run option as mentioned in below screenshot to run pipeline. When pipeline start executing, it ask for permission to access secure variables and secure keystore file, grant these permission to pipeline.

Step 12 : Once pipeline execution completed, you can see pipeline execution and its status as shown in below screenshot.

Step 13: To see summary of execution of particular pipeline you can click on pipeline execution as mentioned in step 12 and you will see summary as shown in below screenshot. if you want to download apk and other published artifcats then you can click on “published” option as mentioned in below screenshot and then you can see and download those artifacts.

Here we completed CI for Android project using Azure DevOps.

If you like this Part 1, please click on clap icon. If you have suggestions and comments, please add that in comments section. You can read Part II by clicking here.

--

--

Anil Sisodiya

I am Software Architect with 18+ years of experience. I worked on many mobile application, which belong to various domain from scratch to production.