Pre-create App Center app in your Azure Pipeline

Max Yermakhanov
ObjectSharp (a Centrilogic Company)
2 min readMar 10, 2020

AppCenter is pretty good when it comes to builds, distribution, testing, event handling, etc. for your mobile apps. You can easily integrate AppCenter with your Azure Pipeline. With just a few lines of YAML (or a few clicks, if you prefer classic pipeline editor), you can build yourself a full end to end pipeline for your mobile apps. It’s easy.

One of the things that I wish Azure Pipelines tasks for AppCenter had is to create AppCenter app if it’s missing. Luckily AppCenter has a very extensive REST API that helps us to fill that void. Below is a bash script that create AppCenter app if it does not exist in AppCenter:

APPCENTER_ORGANIZATION=ENTER_APPCENTER_ORGANIZATION_NAME_HERE
APPCENTER_API_TOKEN=SET_VIA_AZURE_PIPELINE_VARIABLES_HERE
APP_NAME="ENTER_YOUR_APP_NAME_HERE"
APP_OS="ENTER_YOUR_APP_OS_HERE"
APP_PLATFORM="ENTER_APP_PLATFORM_HERE"
echo "Checking for $APP_NAME app"
appExists=$(curl -X GET "https://api.appcenter.ms/v0.1/apps/$APPCENTER_ORGANIZATION/$APP_NAME" --header 'X-API-Token: ${$APPCENTER_ORGANIZATION}' --write-out "%{http_code}\n" --silent --output /dev/null)
if [ $appExists -eq "200" ]
then
echo "$APP_NAME app already exists in AppCenter"
else
echo "creating $APP_NAME app"
#define JSON body to create an app JSON_STRING='{"description":"'"$APP_NAME"'","display_name":"'"$APP_NAME"'","name":"'"$APP_NAME"'","os":"'"$APP_OS"'","platform":"'"APP_PLATFORM"'"}'
#creating AppCenter app
curl -X POST "https://api.appcenter.ms/v0.1/orgs/$APPCENTER_ORGANIZATION/apps" --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'X-API-Token: ${$APPCENTER_ORGANIZATION}' -d $JSON_STRING
#give it a few seconds to finish the task, then let's validate if app was created successfully in AppCenter
sleep 10
echo "validating $APP_NAME app"
appExistsNow=$(curl -X GET "https://api.appcenter.ms/v0.1/apps/$APPCENTER_ORGANIZATION/$APP_NAME" --header 'X-API-Token: ${$APPCENTER_ORGANIZATION}' --write-out "%{http_code}\n" --silent --output /dev/null)
if [ $appExistsNow -eq "200" ]
then
echo "$APP_NAME app has been created successfully"
else
echo "creating $APP_NAME app failed!" >&2
exit 1
fi
fi

Use Bash task in Azure Pipeline to insert the script above into your pipeline and automatically create AppCenter apps if they don’t exists as a part of your pipeline magic. Hope this helps.

#DevOpsGuy

--

--