Directus Asset

Mobile App Distribution with GitLab for Android Builds

Directus Asset
Martin Mattli
December 12, 2020

In this blog post we would like to show you how easy it is to configure a CI pipeline with GitLab for app distribution with Updraft. In this blog we will deal with the following questions:

  • What is GitLab?

  • What is a CI/CD pipeline?

  • How does app distribution for Android apps work with GitLab and Updraft?

  • How do I configure the .yml file for the app distribution?

What is GitLab?

GitLab is a Git repository tool for versioning and controlling source code changes during software development. The main advantage of a git repository and source code versioning is that multiple developers can code simultaneously without interfering with each other. They can edit the source code, make changes and bug fixes at the same time, and always keep track of all the work they've done on the code. Every single change to the code can be tracked and undone. 

GitLab has evolved into a fully web-based tool for managing the entire development process and lifecycle. In addition to the Git repository, GitLab also offers features for continuous integration, continuous deployment, and has an integrated wiki for documentation and issue tracking.

We at Updraft have been working with GitLab since 2018, after Microsoft announced that it was taking over GitHub.

What is a CI/CD pipeline?

In a previous blog post, we wrote about this in great detail. 

Here is a short summary:

A continuous integration and deployment pipeline (abbreviated to CI/CD pipeline) comprises several steps that must be carried out in order to provide a new version of a software or an application continuously and automatically. This new version can then be installed in the various development environments (test, integration or production environment). With the correct configuration of a CI/CD pipeline and the automation of individual steps, the quality of the software can be increased holistically, because changes in the code can quickly and reliably be integrated (Integration) into the individual development environments and then be delivered (Delivery).

App distribution with GitLab

We are often asked by our users if there is an easy way to distribute apps directly from GitLab. No, this is not possible - BUT with a few simple steps you can integrate Updraft as your app distribution tool into the development and distribution process with GitLab.

The whole setup only takes a few minutes. The only requirement is that you need an account on Updraft. You can use the service of Updraft for free.

Step 1: Create an account on Updraft

  1. Register here to use our free app distribution service.

  2. Create your app project

  3. Create your first Android app within your app project

As soon you have registered successfully and created your first app project:

  1. Go to your Updraft profile

  2. Copy your Updraft API key

  3. Go back to the app overview and copy the app key of your app

The API key is needed to communicate with the app distribution service and the app key is needed to post the binaries/ artefacts from GitLab to the right Updraft app later on.

Step 2:  Configure GitLab CI/CD Settings & Variables

As soon you have created your Updraft account, you are ready to configure the CI/ CD pipeline with GitLab.

  1. Open your GitLab Project

  2. Go to the Settings

  3. Select CI/CD

  4. Go to the section Variables

  5. Click on the “Expand” button

Configure CI/CD pipeline with GitLab

 

Now you need to add the API and the app key from Updraft. You need to add two variables.

  1. For the first variable type in a name for your API key: UPDRAFT_API_KEY

  2. Paste your Updraft API Key in the input variable field (row Value)

  3. Click on Save variables

  4. For the second variable type in a name for your app key: UPDRAFT_APP_KEY

  5. Paste your Updraft app key in the Input Value field

  6. Click on Save variables

 

Save Variables

 

As soon you are done and have clicked on “Save variables” it will look like this:

GitLab with variables

Step 3: Add .gitlab-ci.yml file for app distribution

Now as you have added the GitLab variables you are ready to configure your .gitlab-ci.yml file. The .gitlab-ci.yml file is used to build, test and deploy.

  1. Open your GitLab Project

  2. Open the Repository tab

  3. Go to Files

  4. Click on the + icon to create a new file

  5. Select a template type: choose .gitlab-ci.yml

 

Gitlab navigation and new file

Step 3.1: Define your stages

As soon you have your new file prepared, you are ready to add all CI/CD jobs to your .yml file.

First of all you are defining the different stages of your build. You can name them as you like. A stage can consist of several jobs. Jobs are executed in parallel if they are in the same stage. 

All jobs must be executed before moving on to the next stage (subsequent execution) if multiple stages are defined. You now define a stage: updraft. As soon as an Android app is built, you want to deploy this artifact to Updraft.

Step 3.2 Build

The building of the app is now defined. This is where GitLab is given all the information about the code and the scripts used. 

Step 3.3: Deploy 

In the second section of the .yml file you define the deployment of the app. For this you define:

  1. The stage

  2. The used branch, in this case: release

  3. And you add the curl command to deploy the Android app to Updraft

You are done! 

In case this description is a bit too complex, we added an example in the following section of the blog.

Example of the .gitlab-ci.yml

 

stages:
  - build
  - updraft

buildProd:
  stage: build
  only:
    - release

  script:
    - ./gradlew app:assembleProdRelease

  artifacts:
    paths:
      - app/build/outputs/apk/prod/release/*.apk

deploy:
  stage: updraft
  only:
  - release

  script:
  - |
    curl \
      -F whats_new="Gitlab build" \
      -F "app=@app/build/outputs/apk/ prod/release/android.apk" \
      -X PUT https://getupdraft.com/api/ app_upload/$UPDRAFT_APP_KEY /$UPDRAFT_API_KEY/

 

The location defined with the command -F app=@ is very often the path to the artifact. But make sure to double check and adapt to your structure. That means you don't have to switch to the Jobs tab anymore,  but your app will be deployed to Updraft immediately.

Step 4: Commit and push changes

So now you have configured your CI/CD pipeline. Now push your changes to the branch defined in your .gitlab_ci.yml and check your pipeline. Open the section CI/CD within the left sidebar and open the Pipeline section. 

You can now see the running builds on the Pipelines tab of your project. You can even watch the build live and see the output of the Runner per defined stage, and if problems occur, you can see it immediately.

Step 5: Your testers will automatically be notified as soon a new Android build is ready

If you have added your testers with their email address on Updraft or if you created a group of testers, you can notify them automatically whenever you deploy a new app version. 

  1. Go to Updraft

  2. Choose your App

  3. Select Distribution

  4. Go to Tester & Groups

  5. Add your testers’ email address

All your added testers are now on the distribution list. On the app overview page, you can simply enable the automatic notification of your testers. As soon you deploy a new app version your testers will get notified to install the latest version of your app. App distribution is that easy! 

Summary

We hope you now understand how Updraft integrates with GitLab for the Android app distribution. We would be very happy if you tried it and gave us feedback. 

If you need more information, you'll find lots of information in our documentation.