Automated Build Publishing to Microsoft AppCenter

Mark Dappollone
5 min readJan 27, 2020

HockeyApp is dead, long live AppCenter.

Now that Microsoft has acquired HockeyApp and decided to smash it into AppCenter, some things are changing, and you may be encountering some unexpected consequences of it all. One of these unforeseen complications comes about if you organization previously used HockeyApp, but also has an enterprise subscription to Office 365. If this is the case, you might actually now be seeing two versions of AppCenter, depending on how you sign in… if you sign in with a personal account, you’ll get the AppCenter account that you migrated from HockeyApp, with all your apps transitioned. If you sign in with your NT ID, you’ll get an AppCenter account that belongs to your organization’s Office 365 Suite, which you are logged into by default, and is totally empty.

Cue Panic.

Ok, don’t panic. It’s just that AppCenter thinks you’re your org account, rather than your old HockeyApp account. And since everyone in your org using AppCenter will be auto logged into the empty one… Crap. You have to migrate everything. Again.

Honestly, migrating to a new AppCenter account is no big deal, unless you have a million apps and need all the history of them forever, which, let’s be honest, you probably don’t.

But there is one thing that’s going to be trickier than you think, and it’s automating build publishing into your CI pipeline. I like using curl for calling APIs for this, since we have to use a proxy to get outside our corporate intranet to the web. If you’re doing that too, you might have automation tasks set up to use the simple, easy to use HockeyApp API, which can publish any build of any app in a single line:

curl status=2 -F notify=1 -F notes=$notes -F notes_type=0 -F ipa=@$ buildPath -H X-HockeyAppToken: $hockeyToken https://rink.hockeyapp.net/api/2/apps/upload

There it is, in all its glory. Issuing that one command would upload just about any apk or ipa to HockeyApp, and then HockeyApp would figure out what to do with it. Alas, with AppCenter, nothing is quite that simple and awesome. Luckily, you can get the same result you used to get in one step with HockeyApp, in just 4 easy steps using AppCenter.

Deep Breaths

Unfortunately, AppCenter’s API documentation is almost completely empty, providing next-to-no help at all for integrating their platform into your CI pipeline. Luckily, we’ve (more or less) figured it out, so you can maybe skip the parts where it inexplicably doesn’t work for mysterious reasons, and go right to the part where you don’t have to think about it for a while longer.

Getting Started

For the purposes of this article, and since you had to do it in HockeyApp as well, we’ll assume you already have an API token, so the first thing you need to do is:

1. Find your App’s Info

With AppCenter, you have to use APIs to give AppCenter metadata about your binary, like who owns it and what its name is, so the first step is to find this stuff. You can find this info by visiting the URL for your app, and parsing it into pieces. AppCenter app urls follow the format:

https://appcenter.ms/orgs/$ownerName/apps/$appName/

These names aren’t necessarily the same as the names you set for the owner and app name, since AppCener replaces white spaces with hyphens.

2. Create an Upload Resource

Remember how HockeyApp used to do all the work figuring out what to do with your binary? AppCenter is not gonna do that. So you’ll need 3 APIs to distribute your app. First, you need to create an upload resource. To do this, call the release_uploads API for your app, using the info from step 1. Since I’m using gradle for building and publishing, I’ll create a groovy function to do this:

I’m just using curl here to call the release_uploads API. That API will return a JSON snippet that we’ll parse and use in the next step.

A quick note here about my experience: the AppCenter API Swagger documentation (which is pretty much useless) says that the body is required for this call, but it actually isn’t. In fact, it’s so optional that, when I tried to include it, the entire process described in this article failed with no explanation. Including the body (as described in the swagger) with this API, causes the next API to fail with:

{"errors":{"credentials":"upload_id is not recognized. An Upload resource should be created first."}}

If you get that error, it might be because you’ve included the body on the resource creation API. Chop that off, and you’ll be good to go.

I know you’re missing the HockeyApp API already. But strap in, because this isn’t going to get any better.

That’s not an unreasonable reaction.

2. Parse the Response

Now that you’ve created an upload resource, you’ll need the url and key for that resource that’s returned in the response. If you’re using gradle, Groovy provides a class to do this called JsonSlurper:

3. Upload the Binary

Next, we’ll transmit our binary to AppCenter using a http multipart formpost. For this step, you can send either an APK or an IPA, depending on what type of app you’re distributing.

To upload, you’ll need to post to the upload url you got from the response of the last call. Also, notice that the field name for the actual file you’re uploading is “ipa”, but again, you can use this API to upload an APK as well. That misnomer is one of the few things carried over from the HockeyApp API.

4. Commit the Change

Last but not least, AppCenter wants you to confirm that you actually want to make available the resource you just uploaded. This is where you’ll use the upload_id from the response of the first API call.

And that, as they say, is that. You should be able to go to AppCenter, and under the “Distribute” tab of your app, you should see your upload under “Releases.”

Flawless execution.

To sum up, AppCenter is here and there’s no going back. But, at least you can get going again, while you consider another option for app distribution.

--

--

Mark Dappollone

Director, Mobile Product Engineering at Anywhere Real Estate