0
votes

We've developed Azure Mobile service with .Net backend. We can publish it from VisualStudio, but we'd like to automate the process to publish the service from a build machine.

We'd like to have the build and publish processes separated, so the solution which combines building and publishing described there is not sufficient for us.

Are there any powershell/command line tools for Azure Mobile Services, similar to New-AzureDeployment/Set-AzureDeployment (ref: "Deploying cloud services to Azure with Powershell")?

2

2 Answers

2
votes

For Azure Mobile Services, you can deploy via git - the mechanism would be that you check your "production" code into a git repository. This can be automated as part of your continuous integration tests - see the following walkthrough: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-store-scripts-source-control/. This is probably your best bet for automation.

You can also use the azure command line tool. See the following walkthrough for details: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-manage-command-line-interface/

0
votes

I finally managed to get it working using MSDeploy.exe. I found out that running msbuild with "/p:DeployOnBuild=true", but without "/p:PublishProfile" doesn't actually publish mobile service, but creates the folder with contents, that can be published with msdeploy.

Steps which should be followed to publish mobile service using msdeploy:

Within building process:

  1. Add /p:DeployOnBuild=true to msbuild command that builds mobile service
  2. The publish folder is created in obj\Release\Package. This folder contains PackageTmp folder as well as a few files (.cmd, .xml, .zip) which are supposed to be used during publishing. However I couldn't get it working with these files. In my case PackageTmp folder was what I needed and I copied this folder to the output of build process.

Within publishing process:

  1. (only once) Download publish profile (.publishsettings file) for the mobile service from Azure Management portal (link available on Dashboard tab)
  2. Run the batch which runs msdeploy.exe:


    @echo off
    if "%MSDeployPath%" == "" (
    for /F "usebackq tokens=1,2,*" %%h  in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" /s  ^| findstr -i "InstallPath"`) do (
    if /I "%%h" == "InstallPath" ( 
    if /I "%%i" == "REG_SZ" ( 
    if not "%%j" == "" ( 
    if "%%~dpj" == "%%j" ( 
    set MSDeployPath=%%j
    ))))))

    "%MSDeployPath%"\msdeploy.exe -verb:sync -source:contentPath=<path_to_PackageTmp_folder> -dest:ContentPath=<mobile_service_site>,PublishSettings=<path_to_downloaded_publishsettings_file>,AuthType='Basic' -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension

Alternatively it is possible to compress contents of the mentioned PackageTmp folder into a zip and change the publish line to:


    "%MSDeployPath%"\msdeploy.exe -verb:sync -source:package=<path_to_zip_file> -dest:ContentPath=<mobile_service_site>,PublishSettings=<path_to_downloaded_publishsettings_file>,AuthType='Basic' -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension

A few times I had to restart mobile service after publishing. It can be easily accomplished with Azure CLI.

I hope the above helps someone, who would like to automate mobile service deployment process :-)

The article which helped me to get it all done: Azure Mobile Service deployment with Team City part 4. Deploying Azure Mobile Services