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?
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.
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).
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.
Register here to use our free app distribution service.
Create your app project
Create your first Android app within your app project
As soon you have registered successfully and created your first app project:
Go to your Updraft profile
Copy your Updraft API key
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.
As soon you have created your Updraft account, you are ready to configure the CI/ CD pipeline with GitLab.
Open your GitLab Project
Go to the Settings
Select CI/CD
Go to the section Variables
Click on the “Expand” button
Now you need to add the API and the app key from Updraft. You need to add two variables.
For the first variable type in a name for your API key: UPDRAFT_API_KEY
Paste your Updraft API Key in the input variable field (row Value)
Click on Save variables
For the second variable type in a name for your app key: UPDRAFT_APP_KEY
Paste your Updraft app key in the Input Value field
Click on Save variables
As soon you are done and have clicked on “Save variables” it will look like this:
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.
Open your GitLab Project
Open the Repository tab
Go to Files
Click on the + icon to create a new file
Select a template type: choose .gitlab-ci.yml
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.
The building of the app is now defined. This is where GitLab is given all the information about the code and the scripts used.
In the second section of the .yml file you define the deployment of the app. For this you define:
The stage
The used branch, in this case: release
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.
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.
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.
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.
Go to Updraft
Choose your App
Select Distribution
Go to Tester & Groups
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!
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.