This article describes how to setup Windows Azure Web Role (Cloud Service) deployment using the automated continuous integration server CruiseControl.NET. This process enables you to automatically create a package and deploy it to Windows Azure after every code check-in. The package build process is equivalent to the Package command in Visual Studio. For building the package we will use MSBuild command-line, for deployment Windows PowerShell script. The build and deployment process can be customized based on your Windows Azure environment, development, staging or production.
Powershell script is based on the script provided by Continuous Delivery for Cloud Applications in Windows Azure.
Configure Build Server
I'm assuming that you already have .NET Framework installed on the build machine and are using Visual Studio 2012. Next steps:
Install the Windows Azure Authoring Tools - WindowsAzureAuthoringTools-x64.msi.
Copy the Microsoft.WebApplication.targets file from a Visual Studio installation to the build server. File is located in the following directory:
C:\\Program Files
(x86)\\MSBuild\\Microsoft\\VisualStudio\\v11.0\\WebApplications
Copy it to the same directory on the build server.
3. Install Windows Azure Tools for Visual Studio - WindowsAzureTools.VS110.exe
Configure Build Command
Now we need to configure the build for the Cloud Service project.
<exec description="Build Azure Deployment Package">
<executable>C:\\WINDOWS\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe</executable>
<buildArgs>"c:\\Builds\\IAmMec\_DEV\\Code\\IAmMecCloudService\\IAmMecCloudService.ccproj"
/target:publish /p:Configuration=Release /p:TargetProfile=Development
/p:PublishDir=c:\\Builds\\IAmMec\_DEV\\temp\\</buildArgs>
<buildTimeoutSeconds>300</buildTimeoutSeconds>
</exec>
We have separate configurations for each environment. The appropriate environment is chosen by specifying a target profile. E.g. for Development environment specify: /p:TargetProfile=Development
This command will output the deployment package and configuration to the specified directory (/p:PublishDir). In our case that would be:
IAmMecCloudService.cspkg
ServiceConfiguration.Development.cscfg
Configure PowerShell Script
Windows Azure PowerShell is a scripting environment that you can use to automate the deployment and management of your Windows Azure services. In order to use it, we need to install Windows Azure PowerShell cmdlets.
Start Windows PowerShell using the Start menu. Verify that the PowerShell cmdlets are available by typing the command Get-Module -ListAvailable. The list should contain Azure module:
The next step is to download the publish settings profile. We will need to specify the settings file when calling PowerShell script.
Once we have our deployment package, service configuration, and publish settings file, we can proceed with publishing them using Windows Powershell script. Download the Script Template and set up the default parameters. It's up to you if you specify all parameters or pass them when executing the script. Add or modify any parameter values in the Params section. These values can always be overridden by passing in explicit parameters.
Param( $serviceName = "iammec-dev",
$storageAccountName = "iammecdev", $packageLocation = "c:\\Builds\\IAmMec\_DEV\\temp\\IAmMecCloudService.cspkg", $cloudConfigLocation = "c:\\Builds\\IAmMec\_DEV\\temp\\ServiceConfiguration.Development.cscfg ", $environment = "Production", $deploymentLabel = "Development", $timeStampFormat = "g", $alwaysDeleteExistingDeployments = 1, $enableDeploymentUpgrade = 1, $selectedsubscription = "MEC Development", $subscriptionDataFile = "c:\\Builds\\IAmMec\_DEV\\IAmMec.publishsettings" )
You need to make sure that PowerShell is able to execute the script. By default, the execution policy is set to restricted. That means that you will only be able to access signed scripts. You can change that by setting the execution policy to RemoteSigned or Unrestricted:
Set-ExecutionPolicy RemoteSigned
This will enable you to run scripts that you write yourself, but will not run scripts downloaded from the Internet if the scripts have not been signed by a trusted publisher.
If your machine is 64-bit and CCNET is running as 32-bit process you will need to set the execution policy for 32-bit powershell. Or just do it for both of them:
32-bit PowerShell C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
64-bit PowerShell C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
The last thing to add to your CCNET configuration is the execution of that script:
<powershell>
<script>PublishCloudService.ps1</script>
<executable>c:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe</executable>
<scriptsDirectory>c:\\Builds\\IAmMec\_DEV\\</scriptsDirectory>
<buildArgs></buildArgs>
<successExitCodes>0,1</successExitCodes>
<buildTimeoutSeconds>600</buildTimeoutSeconds>
<description>Deploy to Windows Azure.</description>
</powershell>
Make sure you specify a high enough build timeout value. You can adjust that based on your needs, but give it at least 10 minutes.
It is best to tune those command lines and scripts before adding them to CCNET configuration. It will just save you time and will not pollute your reports with failed builds.
Happy continuous integration using Windows Azure!