How to setup AppCenter with GitLab Without Pushing Secret Files
We can all agree that having a tool to automate app builds, distributions and even analytics can be quite nice. Well, this is exactly what AppCenter does. And more.
For those of us who use GitLab as their main Git server, it can be quite frustrating setting up GitLab to work with AppCenter. It took me a day to figure out how to work some things out, and now I would like to share it!
In order to make AppCenter work "with" GitLab, we first have to mirror our repository to BitBucket. So go ahead and create a repository in BitBucket, then go to your user's
Settings (not repo settings, still in BitBucket) and create a new app password under
App passwords with all available permissions, and copy the password you are given for later.
Then go to GitLab,
Repository, and under
Mirroring Repositories, enter your BitBucket clone URL, choose
Password as auth method, and paste in the password you've been given in BitBucket. Click
Mirror Repository and you should see a new row in the table below. Click the refresh button on the right to sync the repository.
Now that was the easy part. Now we need to integrate AppCenter and hide some secrets
Go to AppCenter, and create a user if you don't already have one. Create your apps (For me it was one for Android and one for iOS) and complete the steps to add App Center’s SDK. Now go to
Build, and select
Select a Service. Select your newly created repo, and then you should see all of your branches. That's it for now.
Now in order for AppCenter to build our application, it needs our app's AppCenter secret (which you are given in settings, shown below), and if you use Firebase like me, it also needs the
google-services.json file (for Android) and
GoogleService-Info.plist for iOS. So what we need to do is to inject them before we build…. Let's write it down!
Our file will be called
appcenter-pre-build.sh so AppCenter will run it before building:
This code is for both platforms, you can edit it how you want.
Now the last thing there is to do is inserting the environment variables!
As our code shows, we have 4 environment variables. Let's go to the build configuration again, expand
Environment Variables, and add our 4 variables:
Make sure to base64 encode the JSON values before entering them!
(You can use this site)
Now our build should run, and show
Injecting secrets… somewhere in the middle :)