Azure Mobile Service deployment with Team City part 4. Deploying Azure Mobile Services

Tags: Azure, Powershell, TeamCity

In the previous post I explained how to run a set of steps including restoring NuGet packages, building and running Unit Tests using psake with PowerShell.

The last step in our pipeline is the deployment script. This post will be shorter than others because it describes only the deployment of Azure Mobile Services. Basically this deployment issue triggered me to write an entire set of blog posts. At the moment Microsoft doesn’t provide a way of deploying Azure Mobile Service from the command line. The only option you have is using Visual Studio. But you can’t achieve much automation using Visual Studio.

I will create the deployment step in a separate script so we can use the same script when deploying on other environments. The script name is deploy-package.ps1 and it contains a few parameters.

packageLocation – this is the location where our package is stored. The location was defined during the build step. It was defined in $artifactDirectory variable which in our case was set to “[Root]\Artifacts”. We’ll configure this in TeamCity as well so we can reuse artifacts for deployments in other environments.

The rest of parameters are not really straightforward, we need to extract them from the Mobile Service Publish Profile. In Azure Management Portal open your Mobile Service you want to deploy to and click on the Dashboard. There should be “Download publish profile” link. Click on it and download the profile. The profile file is an XML file. Open it in a text editor like Sublime or Notepad++ and format the XML to be easier to read. The profile contains two publishing methods: MSDeploy and FTP. We’ll look at the MSDeploy. Search for the MSDeploy in publishMethod attribute and that will be the publishProfile XML element we’ll be looking at.

contentPath – search for msdeploySite and that will be the value you need. It should have the form of mobile$[MOBILE-SERVICE-NAME]

computerName – This was a bit difficult to figure out because you don’t have the value in the publish profile file. We’ll construct the value from different parts. Search for publishUrl in the profile file. My value is similar to this To construct the computerName we’ll get the publishUrl value till the port number, for example and append this at the end /msdeploy.axd?site=[deploySite] . Replace the deploySite with the deploySite attribute value from the profile file. Also add https:// in front. At the end you should have a value similar to this:$my-mobile-service

userName – get the userName from the publish profile

password – get the password value from the publish profile

In order to deploy the mobile service we are going to use msdeploy application. You should have it installed on your machine but it’s missing from the Azure VM. Remote into the VM, download it from the and install it.

MsDeploy will be executed with these parameters

msdeploy.exe -verb:sync -source:contentPath=[PACKAGE_LOCATION] -dest:ContentPath=[CONTENT_PATH],ComputerName=[COMPUTER_NAME],UserName=[USER_NAME],Password=[PASSWORG],AuthType='Basic'

This is the source code which will deploy the package

function DeployPackage

    $webDeployExePath = "C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\"

    $msdeploy = "$webDeployExePath\msdeploy.exe"
    if (!(Test-Path $msdeploy)) {
        throw "msdeploy.exe could not be found on this machine. MsDeploy location: $msdeploy"

    "***** Start deploying the package from loction: $packageLocation *****"

    $arg1 = "-verb:sync" 
    $arg2 = "-source:contentPath=$packageLocation"
    $arg3 = "-dest:ContentPath='$contentPath',ComputerName='$computerName',UserName='$userName',Password='$password',AuthType='Basic'"

    & $msdeploy $arg1 $arg2 $arg3 $arg4


Now you should be able to build and deploy the Mobile Service to Azure instance from your machine. In the next post we’ll configure TeamCity to do this for us.


< Previous


comments powered by Disqus