Using Custom Deployment Scripts with Windows Azure Websites

  • 27 Jun 2014

  • Dan Lister


Automating deployments is a must when building an application. We've been using Windows Azure Websites to host our Umbraco solutions for a while. We wanted to step away from our TeamCity server as it adds another level of complexity to our deployments. Fortunately, deployment slots and custom deployment scripts have allowed us to remove our build server completely and rely solely on Azure's website deployment service, Kudo. Here are a couple of steps of how we step custom deployments.

Create a Deployment Slot

For all our websites, we have two environments. Each website resource in Azure acts as our production environment which is linked to our master branch, in our git repositories. We also have a deployment slot which acts as our development environment. This is linked to our development branch, in our git repository. To create a development deployment slot, navigate to your website and choose the create deployment slot option, naming it appropiately. In our case, development.

Link your Repository

Once your deployment slot has been created, connect your environment to your git repository. Also amend the branch name to development within the configuration tab of your website. This will build out your solution from the git repository's development branch.

Deploy

Manually trigger a deployment from the deployment tab within your website. When you trigger a deployment within your website, Kudo will generate a deployment script which will compile and sync your repository with the website.

Find the Deployment Script

The generated deployment script can be obtained from your website's FTP location. Login details can be found on your website's dashboard. Once you have logged in via FTP, navigate to the /site/deployment/tools folder and find a file called deploy.cmd. This is your deployment script.

Add to your Repository

Add the deploy.cmd to a location within your git repository. We like to have a build folder which contains all build related files. To trigger your deployment script when your repository branch is built, add the following .deployment file to the root of your repository.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

Show hidden characters

[config]
command = Build\deploy.cmd

view raw .deployment hosted with ❤ by GitHub

Add Web.config Transformations

Within your Visual Studio solution and projects, create build configurations which match the branch names of your git repositories. This will allow you to specify which web.config transform is completed upon building your application. To correctly build the correct configuration when deploying, a service variable called &branch& is available for you to pass to your msbuild command in your deployment script. Find the msbuild call within your script and changed the configuration property to &branch&. It should hopefully look like the below.

Show hidden characters

IF /I "%IN_PLACE_DEPLOYMENT%"NEQ"1" (
call :ExecuteCmd"%MSBUILD_PATH%""%DEPLOYMENT_SOURCE%\Source\Website\Project.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="%DEPLOYMENT_TEMP%";AutoParameterizationWebConfigConnectionStrings=false;Configuration=%branch% /p:SolutionDir="%DEPLOYMENT_SOURCE%\Solution\.\"%SCM_BUILD_ARGS%
) ELSE (
call :ExecuteCmd"%MSBUILD_PATH%""%DEPLOYMENT_SOURCE%\Source\Website\Project.csproj" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=%branch% /p:SolutionDir="%DEPLOYMENT_SOURCE%\Solution\.\"%SCM_BUILD_ARGS%
)

view raw deploy.web.config.cmd hosted with ❤ by GitHub

Add File Transformations

We often have to transform other files. For example, Umbraco's settings file or log4net configuration files. As far as I'm aware, msbuild will only transform web.config files. To fix this problem, in our build folder we create a log4net.dev.config and a log4net.master.config file. Using the &branch& service variable, we add a copy command to our deployment script to copy across the correct environment file. This command must be added before the solution is built.

Show hidden characters

call :ExecuteCmdcopy"%DEPLOYMENT_SOURCE%\Build\Transforms\log4net.%branch%.config""%DEPLOYMENT_SOURCE%\Source\Website\config\log4net.config"
call :ExecuteCmdcopy"%DEPLOYMENT_SOURCE%\Build\Transforms\robots.%branch%.txt""%DEPLOYMENT_SOURCE%\Source\Website\robots.txt"

view raw deploy.other.config.cmd hosted with ❤ by GitHub

And that's pretty much it. You should have an application which can be deployed to multiple environments using a custom deployment script to run custom commands such as copying environment config files.


Disqus Comments

We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

G

Join the discussion…

Comment

Log in with
or sign up with Disqus or pick a name

Disqus is a discussion network

  • Don't be a jerk or do anything illegal. Everything is easier that way.

Read full terms and conditions

This comment platform is hosted by Disqus, Inc. I authorize Disqus and its affiliates to:

  • Use, sell, and share my information to enable me to use its comment services and for marketing purposes, including cross-context behavioral advertising, as described in our Terms of Service and Privacy Policy, including supplementing that information with other data about me, such as my browsing and location data.
  • Contact me or enable others to contact me by email with offers for goods or services
  • Process any sensitive personal information that I submit in a comment. See our Privacy Policy for more information

Acknowledge I am 18 or older

I'd rather post as a guest

Favoriting means this is a discussion worth sharing. It gets shared to your followers' Disqus feeds, and gives the creator kudos!

Find More Discussions

Share

Huge help. thanks.

see more

Show more replies

T

Nice article Dan! If you want to have transforms for your other config files, check out SlowCheetah. It allows you to have the same functionality that you have for web.config, but for any XML based config files in your solutions. It's really handy for having different versions of the various Umbraco/Package config files for different environments!

see more

Thanks Tim and thanks for the tip. I'll give SlowCheetah a nosey :)

see more

Load more comments

live.rezync.com

live.rezync.com is blocked

This page has been blocked by an extension

  • Try disabling your extensions.

ERR_BLOCKED_BY_CLIENT

Reload

This page has been blocked by an extension

pippio.com

pippio.com is blocked

This page has been blocked by an extension

  • Try disabling your extensions.

ERR_BLOCKED_BY_CLIENT

Reload

This page has been blocked by an extension