Skip to content

Instantly share code, notes, and snippets.

@AdamGold AdamGold/blog.md Secret
Created Mar 7, 2019

Embed
What would you like to do?

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.

Easy

However...

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!

BitBucket Mirroring

Screen Shot 2019-03-07 at 18.04.30

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.

Screen Shot 2019-03-07 at 18.13.21

Then go to GitLab, Settings -> Repository, and under Mirroring Repositories, enter your BitBucket clone URL, choose Push under Mirror Direction, 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.

Setup AppCenter

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 BitBucket under Select a Service. Select your newly created repo, and then you should see all of your branches. That's it for now.

Build Scripts

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!

Screen Shot 2019-03-07 at 18.04.00

Our file will be called appcenter-pre-build.sh so AppCenter will run it before building:

https://gist.github.com/2e0400c6fddfbb51b7521c495abc6c2f

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!

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:

GOOGLE_SERVICES_JSON, GOOGLE_SERVICES_PLIST, ANDROID_SECRET, IOS_SECRET.

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.