App Center to Azure DevOps: how to check your app build status in a Pipeline

Ant Puleo
Ant Puleo
Oct 3 · 2 min read

Here at CorLife, we try to automate as much as possible. This can be challenging for a mobile app.

We use App Center to build our app because it’s easy to set up and configure, while we use Azure DevOps for managing our repos. Reporting back to Azure DevOps the app build status isn’t a feature that’s currently available, though.

There is hope, however, through the use of the Invoke Function Task.

How do I do that?

Start by creating a Generic Service Connection in your Azure DevOps project settings. Name it something like “App Center Connection” and give it the Server URL for your app: https://appcenter.ms/api/v0.1/apps/{your-app-name}.

Next, copy the following pipelines scripts and add them to the root of your project:

Then generate an API token in API Tokens section in App Center. Give it Full Access.

You’ll need a build pipeline set up for your project, which will read the azure-pipelines.yml file and you’ll also need to pass in that API token from above as a pipeline variable (I’ve called mine APP_CENTER_API_KEY).

So you’ll notice we query the /branches end-point to get a list of the most recent branch builds. The magic then happens in our successCriteria field, where we’re basically saying parse the JSON and check that there exists a branch object where the latest build has succeeded for either the current PR commit hash:

jsonpath('$[?(@.lastBuild.sourceVersion==''$(System.PullRequest.SourceCommitId)'')].lastBuild.result')[0], 'succeeded')

or latest branch commit hash:

jsonpath('$[?(@.lastBuild.sourceVersion==''$(Build.SourceVersion)'')].lastBuild.result')[0], 'succeeded')

We need to check against both System.PullRequest.SourceCommitId and Build.SourceVersion because the latest commit hash will appear in only one of these variables, depending on whether a PR is open or not.

So in an open PR, System.PullRequest.SourceCommitId will contain the latest commit hash on the branch requesting to be merged in. Otherwise, Build.SourceVersion will contain the latest commit hash on the branch, which is the case for the master branch, for example.

And that’s pretty much it! I did experience some pain in parsing the JSON, but guides here should help:

And here’s the github repo.

Thanks!

Ant Puleo

Written by

Ant Puleo

React Native/Android mobile app developer.

Building corlife

Building the CorLife product

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade