I am constantly asked to talk about DevOps and what DevOps means for Microsoft. Although there are many definitions of DevOps floating out in our industry, at Microsoft, DevOps is the merging of people, process and products such that we can continually deliver value to our end users. And clearly, VSTS/TFS and Azure are the products which enables this whole DevOps mindset.
Randy Pagels and I created a DevOps demo which show how VSTS/TFS and Azure can do this. For the next couple of blogs, I will walk you through how to set up our DevOps demo using an asp.net website backed by sql server hosted in Azure. Source control, work item tracking, CI builds and CD pipelines , unit tests, automated ui tests and load tests are all done using VSTS.
All artifacts for this blog series can be found here:https://github.com/abelsquidhead/MercuryHealth
Table Of Content
Part 1: Setting up your Azure PaaS Environment
Part 2: Setting up your VSTS Team Project
Part 3: Setting up your Git Repo
Part 4: Setting up your Build
Part 5: Setting up your Release Pipeline
Part 6: Full Demo Walkthrough
Release Pipeline
Setting up the release pipeline for this demo will require installing two custom build/release tasks. One will tokenize your configuration files. The other will swap web deployment slots. In order to upload custom build/release tasks, you will need to use the tool TFS Command Line Utility, or tfx-cli for short. To install tfx-cli, do steps 1 and 2 from the following blog:
After installing tfx-cli, proceed to the following steps to upload the config tokenizer task to your vsts instance
Uploading custom build/release task to swap web deployment slots
- Bring up a command line box and browse to where you downloaded the demo and type dir. Notice the full path to where you downloaded the demo and the directory SwapWebSlot
- Type in tfx build tasks upload –task-path .\SwapWebSlot
Uploading custom build/release task to tokenize configuration files
- Bring up a command line box and browse to where you downloaded the demo and type dir. Notice the full path to where you downloaded the demo and the directory ConfigTokenizer
- Type in tfx build tasks upload –task-path .\SwapWebSlot
Set your azure account as a service endpoint
In order to deploy to Azure, you need to add your azure account as a service endpoint in VSTS. If you have already done this, you can skip these steps.
- Browse to the MercuryHealth VSTS portal and click on the gear icon in the upper right hand corner
- Click on the Services tab
- Click on the green plus for New Service Endpoint and select Azure
- This will bring up the Add New Azure Connection Dialog. Click on the Certificate Base radio button, give your azure connection a name , then click on the publish settings file
- This will take you to an azure login page, enter in your azure credentials. After entering your azure credentials, this should download your Microsoft azure consumption file. Open the file and copy your subscription id, name and certificate into the dialog box and click ok
- This should add your azure subscription as a service endpoint
Set up your load test connection
One of the deployment steps will be to run cloud based load tests against your application. You will need to set up a load test connection in your VSTS instance.
- Browse to the MercuryHealth VSTS portal
- Click on the Services tab
- Click on the green New Service Endpoint button and select Generic
- Enter LoadTestConnection for Connection Name, enter in the URL to your VSTS instance for Server URL (i.e. https://abelsquidhead.visualstudio.com), enter in your User Name and Password and click OK
Configuring Release Pipeline
For this demo, you will create a release pipeline that has Dev, QA, BlueGreen and Production environments. For each environment, you will be configuring approvers, setting up environment specific variables and setting up deploy tasks.
For the dev environment, your deployment tasks will consist of deploying the web app, deploying the database schema to the dev database, massaging your configuration files so they point to environment specific values and running both your Selenium automated UI tests against the dev environment and running your coded ui tests against the dev environment.
For the QA environment, your deployment tasks will consist of deploying the web app, deploying the database schema to the qa database, tweaking your configuration files so the point to the correct environment specific values and running an even bigger set of Selenium automated UI tests, and finally running some cloud load tests against the QA environment.
For the BlueGreen environment, your deploy tasks will consist of deploying your web app, deploying your database schema, tweaking the configuration files and running a set of automated ui tests against the bluegreen environment.
And finally the Production environment, your deploy tasks will consist of swapping the deployment slots between the BlueGreen slot and the Production slot.
Configure your Dev environment
- Browse to your VSTS web portal and click on the Release hub
- Click on the green plus to create a new release pipeline. This will bring up the Deployment Templates dialog. Click on Empty and then click the Ok button
- Type in MercuryHealthRelease for Definition, click on Default Environment and change the environment name to Dev
- Click on the ellipses on the Dev environment, then select Assign approvers
- This brings up the Configure – ‘Dev’ Environment dialog. Select Automatic for the Pre-deployment approver and then select Specific User for the Post-deployment approver. Now type in your identity for the specific Post-deployment approver for the dev environment and click the queue .
- Select MercuryHealthPool for Deployment queue and click Variables
- Add the variable name Database.Password, put in the password to the database in value, the click the lock icon
- Click the green Add variable, then type Token.AppUrl for Name, the url to your dev slot for Value
- Click the green add variable, type in Token.BrowserType for Name and chrome for Value, then click on Deployment conditions
- Select After release creation for Trigger, then click OK
- Click on the green Add task button
- This brings up the Add Task dialog box. Click on Deploy, then select the Azure Web App Deployment task and click the Add button, then click the Close button
- Click on the Azure subscription dropdown and select Internal Azure, then enter in the name of your web app in Web App Name, select the web app location that matches your web app location and enter dev for the slot. Enter $(Agent.ReleaseDirectory)\MercuryHealth\**\*.zip as the Web Deployment Package
- Click on the green Add Task button. This will bring up the Add Task dialog
- Click on Deploy, then click on Azure SQL Database Deployment and click Add, then Close
- Click on the Azure SQL Database Deployment Taska. Select Azure Classic for Azure Connection Type
b. Select Internal Azure for Azure Classic Subscription
c. $(Agent.ReleaseDirectory)\MercuryHealth\drop\src\MercuryHealth.Sql\bin\Release\MercuryHealth.Sql.dacpac for DACPAC File
d. Enter the name of your Azure sql server. You can find this in your Azure Portale. You must enter the fully qualified name. Mine is abelmercuryhealthdemodbserver.database.windows.net
e. Enter in the database name for your dev environment
f. Enter in the admin user
g. Enter in $(Database.Password) for Password
h. Enter /p:BlockOnPossibleDataLoss=false for Additional SqlPackage.exe arguments
i. Select AutoDetect for Specify Firewall Rule Using
j. Check Delete Rule After Task Ends - Click on the green add task button
- Click on Utility, click on Configuration Tokenizer, click on Add, then click on Close
- Click on Configuration Tokenizera. Enter $(System.DefaultWorkingDirectory)/MercuryHealth/drop for Working Directory
b. Enter the following for Tokens (separate the tokens with a newline):
__AppUrl__ = $(Token.AppUrl)
__BrowserType__ = $(Token.BrowserType) - Click on the green add task button
- Click on Test, Visual Studio Test task, Add button, then Close button
- Click on the Visual Studio Test task, then enter TestCategory=UITests for Test Filter Criteria, check the Code Coverage Enabled checkbox, enter Selenium Dev UI Tests for Test Run Title under Reporting Options.
- Click on the green Add task button
- Click on Test, click the Visual Studio Test task and the Add button, then the Close button
- Click on the second Visual Studio Test task, enter TestCategory=IETests for Test Filter Criteria, check Code Coverage Enabled and enter Coded UI Dev UI Tests for test run title.
- Click Save Definition.
Create your QA environment
- Click on the Ellipses in the Dev environment and select Clone Environment
- Enter in QA for the environment name
- Click on the ellipses on the QA environment and select Configure variables
- Enter in the correct password for your qa database and the correct url to the qa environment and enter chrome for your Token.BrowserType, then click the Deployment Conditions
- Select after successful deployment on another environment and the select Dev for Triggering environment and the click on Approvers
- Select Specific User for Pre-Deployment approval and enter your user id and click OK
- Click on the Azure Web App Deployment task and change the slot to qa
- Click on Azure SQL Database Deployment, enter in the name of your qa database for the database name
- Click on the first Visual Studio Test task, enter TestCategory=UITests|TestCategory=UITestsBroken for Test Filter Criteria, Enter Selenium QA UI Tests for Test Run Title
- Delete the second test run title by clicking the “x” in the upper left hand corner of the task
- Click the green add task button
- Click Test, then the Cloud-based Load Test task, then click the Add button and the Close button
- Click on the Cloud-based Load Test taska. Registered connection: LoadTestConnection
b. Test Settings File:
$(Agent.ReleaseDirectory)\MercuryHealth\drop\src\MercuryHealth.LoadTests\bin\Release\Cloud.testsettings
c. Load Test Files folder:
$(Agent.ReleaseDirectory)\MercuryHealth\drop\src\MercuryHealth.LoadTests\bin\Release
d. Load Test File Name:
MercuryHealth.loadtest
e. Enter 3 for Number of permissible threshold violations
f. Check enabled,
g. Check Always run
Create the BlueGreen Environment
- Click on the ellipses in the Dev environment and select Clone environment
- Name the new Environment BlueGreen
- Click on the Azure Web App Deployment, enter BlueGreen for Slot
- Click on Azure SQL Database Deployment, enter the name of your production database for Database Name
- Delete the last Visual Studio Test task by clicking on the x in the upper right hand corner of the task
- Click on the ellipses in the BlueGreen and click on Assign Approvers
- Select Specific Users under Pre-deployment approver and select your own identity and click Variables
- Enter the url for the BlueGreen environment for the Value for Token.AppUrl and click Deployment conditions
- Click After successful deployment on another enviornment and the select QA and then click OK
Create Production Environment
- Click on the green Add environment button
- Select Empty and click the OK button
- Name your new environment Prod
- Click on the green Add tasks button
- Click Deploy, scroll down and click Swap Web Deployment Slot and click the Add button and click the Close button
- Click on the Swap Web Deployment Slot task and select Internal Azure for Azure Subscription, Enter the name of your web app in Web App Name, select the location of your web app, enter BlueGreen for slot 1 and production for slot 2 and click the Save button
Link Release Pipeline to Build
- Click the Link to a build definition link
- Select Build for Type, Your project name for the project name and MercuryHealth for the Source (build definition) then click the Link button
- Click the save button
Setting up a DevOps demo using VSTS and Azure (Or DevOps Nirvana with VSTS and Azure), Part 4/5
[…] Part 5: Setting up your Release Pipeline […]
Setting up a DevOps demo using VSTS and Azure (Or DevOps Nirvana with VSTS and Azure), Part 3/5
[…] Part 5: Setting up your Release Pipeline […]
Setting up a DevOps demo using VSTS and Azure (Or DevOps Nirvana with VSTS and Azure), Part 1/5
[…] Part 5: Setting up your Release Pipeline […]
Setting up a DevOps demo using VSTS and Azure (Or DevOps Nirvana with VSTS and Azure), Part 2/5
[…] Part 5: Setting up your Release Pipeline […]
I am facing issues during the deployment part from my Release Pipeline.
Can you help me out here?
Sure, what’s your question?
Hi,
I have completed all steps, in this article in “Create Production Environment” section, i’m trying too add the Swap Web Deployment Slot under deploy section but it is not there in my templates, Please help me to solve this issue.
Thanks & Regards,
Sai Priya. C