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
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
Build
This demo requires a VSTS agent running in interactive mode on a VM. This blog post will walk you through creating a VM that has Visual Studio 2015 update 1 installed in it. This blog post will also walk you through creating CI builds, pull request builds and setting up a policy requiring pull requests for merges into the master branch.
Creating Build VM
- In the azure portal, browse to your resource group and click the plus sign
- Browse down to Dev + test and select Visual Studio
- Select Visual Studio Enterprise 2015 Update 1 with Azure SDK 2.8
- Select Resource Manager as Deployment model and click the Create button
- Give your vm a name, a user name and password and click Select existing for Resource group
- Select Resource group Not configured
- Select the resource group you created for this demo
- Click the OK button
- Choose a D2 for size and click Select
- Click the OK button for settings
- Click the OK button for Summary
- Kick back and relax while Azure builds out your VM
Turn off IE Enhanced Security Configuration
This machine will use IE to run some automated tests. Lof into the vm that you just built and urn off the IE Enhanced Security Configuration
- In your VM, click on Server Manager
- Click on Local Server
- Click on IE Enhanced Security Configuration
- Click on Off for Administrator and Users and the OK button
- Close the Server Manager window
Installing Chrome on the VSTS Build Agent
This machine is used to run your UI Tests. Install Chrome on this machine.
Installing Git on VM
This walkthrough assumes that you already have git installed on your machine. If not, click on Download Git for Windows.
Installing and configuring VSTS agent
- From your virtual machine, browse to your web portal and click the gears in the upper right hand corner
- This brings up the settings portal. From the bread crumb at the top, click on DefaultCollection
- Click on the tab Agent queues
- Click on New queue. This brings up the Create Queue dialog
- Select Create a new Pool and for Pool name, name it MercuryHealthPool and click OK
- Now click Download agent and save the agent.zip onto your drive
- Unzip agent.zip to your hard drive. I placed the contents of agent.zip to C:\VSTSAgent
- Bring up a command box and cd to your directory and run ConfigurAgent.cmd
- Enter a name for this agent, I called mine MercuryHealthAgent
- Enter the url to your VSTS
- Enter the name of the pool you just created (MercuryHealthPool)
- For path of the work folder, just select the default
- For would you like to install the agent as a Windows Server, type in N (we want to be able to run the agent interactively so we can run automated tests). This will pop up a sign in dialog, enter the credentials the agent will use (for this demo, I just entered my ow credentials) and click Sign in
- Your command box should now look something like this
Your agent pool should show your agent running and waiting
- In your command box, turn off the agent by pressing control c and type Y to terminate the batch job
Setting up the VSTS agent to auto login and run in interactive mode on start up
I want my VM to automatically log myself in and start the agent in interactive mode when it boots up to save me from doing this manually every time I boot up my machine
Enable Automatic log in
- Press Windows Key + R to open the Run dialog, type in control userpasswords2 and click OK
- This brings up the User Accounts dialog. Uncheck the box User must enter a user name and password to use this computer, and click the Apply button.
- This brings up the Automatically sign in dialog box. Enter your user name, password and confirm password and click the ok button
- Click OK on the User Accounts Dialog box
Auto start VSTS agent in interactive mode
To start up the agent in interactive mode, you need to run VsoAgent.exe (C:\VSTSAgent1\Agent\VsoAgent.exe). The easiest way to auto start this is to create a shortcut to VsoAgent.exe and then, put the shortcut in the startup folder for Windows.
- Right click the desktop and select New -> Shortcut
- This brings up the Create Shortcut dialog. In the type the location of the item text field, type in cmd and click Next
- In the name of the shortcut, type in StartVSTSAgentS and click Finish
- Right click on the new shortcut and select Properties
- This opens up the StartVSTSAgent Properties dialog. Append /c {pathToVsoAgent.exe} to the target and click OK. For me, I appended /c C:\VSTSAgent1\Agent\VsoAgent.exe. Now click the Apply button, then the OK button
- Double clicking the shortcut should start up the agent in a command box
- Windows Key + r to bring up the Run dialog, type in shell:startup and click OK
- This opens up the startup folder in windows explorer, drag and drop the shortcut you just created to this directory
CI build for pull request
First, we will create a CI build for all pull requests into the master branch.
- Browse to the web portal of your project and click on the Build hub
- Click on the green plus sign, this brings up the Create new build definition dialog. Select Visual Studio and click Next
- This brings up the Create new build definition dialog, click on the Default agent queue and select the MercuryHealthPool and click Create
- This brings up the build definition, because this is just a quick and dirty CI build, we can delete the Index Sources & Publish Symbols task , Copy Files task and Publish Build Artifacts task.
- Click on the Visual Studio Build task and click the ellipses button to select the solution to build
- This brings up the Select Path dialog, open the src folder and select MercuryHealth.sln and click OK
- Click on Visual Studio Test and enter TestCategory=Unit Tests for the Test Filter criteria
- Click on General and select MercuryHealthPool for the Default agent queue
- Click Save, this will bring up the Save dialog, Name this build MercuryHealthCIPullRequest and click OK
build for master branch
Now, we will create a CI build for our master branch.
- Browse to the web portal of your project and click on the Build hub
- Click on the green plus, this brings up the Create new build definition dialog, click on Visual Studio, then the Next button
- Next check the Continuous Integration checkbox, select the MercuryHealthPool in the Default agent queue drop down and click Create
- Click on the Visual Studio Build task and enter the following for the MSBuild Arguments:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=”$(build.stagingDirectory)\drop”
- Click on the Visual Studio Test task and enter TestCategory=Unit Tests in the Test Filter criteria and check the Code Coverage Enabled checkbox
- Click on Copy Files task and change Contents to **\bin\$(BuildConfiguration)\**
- Click the Save button, this brings up the Save dialog, enter MercuryHealth for Name and click OK
Enabling pull request (code review) policy on the master branch
We will set up VSTS so that no one can check code directly into the master branch without doing a pull request (code review) first. We will also set up a ci build for this pull request so when a user initiates a pull request, the pull request build kicks off.
- Browse to the Mercury Health web portal in vsts and click on the gear icon in the upper right hand corner
- Click on the Version Control tab
- In the left hand side tree, open up the MercuryHealth repository and click on master
- Click on Branch Policies
- 5. Under Automatically build pull requests, check “When team members create or update a pull request…” Next, select MercuryHealthCIPullRequest for the Select build definition require drop down. Next, check Block pull request completion unless there is a valid build and click the Save Changes button
Next up, 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 4: Setting up your Build […]
Setting up a DevOps demo using VSTS and Azure (Or DevOps Nirvana with VSTS and Azure), Part 3/5
[…] Part 4: Setting up your Build […]
Setting up a DevOps demo using VSTS and Azure (Or DevOps Nirvana with VSTS and Azure), Part 2/5
[…] Part 4: Setting up your Build […]
Setting up a DevOps demo using VSTS and Azure (Or DevOps Nirvana with VSTS and Azure), Part 5/5
[…] Part 4: Setting up your Build […]