Wednesday, 17 February 2016

ASP.Net 5 (RC1 Update1) Deploy to Azure Website with Visual Studio Team Services Release

How to setup a build with Visual Studio Team Services, for building ASP.Net 5 (ASP.Net Core 1.0 now) is explained in here. Let’s look at steps necessary to create a release pipeline to deploy, ASP.Net 5 website to Azure, with VS Team Service Release.
First requirement is to develop a poweshell script, whcih is capable of deploying, the built ASP.Net package to Azure. Information on how to write such script is available here.image
Script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName

# get the scm url to use with MSDeploy.  By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]


$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword}


$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"


. $publishScript -publishProperties $publishProperties  -packOutput $packOutput
Add this script to version control.image
Modify our release build in previous blog to copy deploy script to build output.image
image
image
Let’s create Azure Web Application as the target.image
image
Site created and ready.image
In Visual Studio Team Services, Release tab create a new empty Release Definition.image
image
To link the release definition to the build created earlier, click on Link to a build definition.image
Select the build definition and link it to release definition.image
Rename the Default Environment to DevInt(Or what ever name you prefer).image
In the DevInt environment create a configuratoin varibale to hold the Azure web site name.image
image
It is possible to set approvers to the stage. So that an approval requires to get the build deploy to the stage/environment DevInt. Let’s set it to autimated and after deployment set a manual approval, to allo get it approved before deploying to next stage/enviornment in the pipeline.image
image
In the release definition add a Azure Powershell task to execute the deployment script. Azure subscription how to link to VS Team Services account can be found here. Set the deployment script to Azure Powershell release task in Dev Intimage
image
For Web Site Name environment variable can be used in the cript arguments.
-websiteName $(WebSiteName) -packOutput $(System.DefaultWorkingDirectory)\Event.Rel\EventRelOutput\image
Eventhough trigger can be set to continuous deployment like below.image
Let’s leave trigger to manua for the time being.image
Now you can trigger a release with the any successful build output you have using the release definition.image
image
image
Build get deloyed to DevInt environment and wait for the post deployment approval.image
DevInt environment site is running now.image
An Improvement to the build number can be made like following.image
Release name format also can be set to use build number for it to be more meaningful.
Release No $(Build.DefinitionName)-$(Build.BuildNumber)-R-$(rev:r)image
Multiple environements in the pipeline can be configured.image
Deployement logs in the pipeline. You can view these logs, while a release is happening.image
Release history can be viewed.image
Release definition change history is available as well t diagnose any issue which might have ocuured with a change to the definition.image
Difference between two defnitions.image
image
New release managment services with VS Team Services is awsome, and let’s explore more in the coming posts.

3 comments:

Tiger said...

Hey there i'm trying your tips to get an asp.net 5 mvc app deployed via release on VSTS.


but i keep running into a problem in which the last step of the release fails saying it can not find website even though the site name variable i'm using is valid and i can see the variable populated with the correct information in the deploy logs.


did you have to make changes to the script at https://www.visualstudio.com/en-us/docs/release/examples/azure/aspnet-core10-azure-web-apps#help-and-support

Tiger said...

Excellent thanks I was able to get his running with a slight modification to your script.

Chaminda Chandrasekara said...

@Tiger.. Great to hear that you have solved the issue :)