Azure Advent Calendar: Azure Devops Pipelines
Tags: azure, azuredevops, pipelines, azureadventcalendar
Published: 2019-12-02 08:32:55

---
title: Azure Advent Calendar: Azure Devops Pipelines
published: true
canonical_url: https://www.funkysi1701.com/posts/azure-advent-calendar-azure-devops-pipelines-5a91
cover_image: https://pixelrobots.co.uk/wp-content/uploads/2019/09/Advent-Calendar.png
description: This blog post is part of Azure Advent Calendar do check out some of the other videos and blog posts
tags: Azure, AzureDevOps, Pipelines, AzureAdventCalendar
---

This blog post is part of [Azure Advent Calendar](https://azureadventcalendar.com/) do check out some of the other videos and blog posts. The YouTube channel can be found [here](https://www.youtube.com/channel/UCJL9wCcmeMBbah4J0uOWIPg)

Azure Pipelines are one of my favourite features of Azure DevOps, so it was the ideal topic for my first video. I am not going to duplicate the content from the video here so go and watch it if you haven't already, but if you have question about anything I said do add a comment below.

{% youtube UM4qI2jVn9M %}

The [Github](https://github.com/funkysi1701/AzureAdventCalendar) and [Azure DevOps](https://dev.azure.com/azureadventcalendar/azureadventcalendar/) accounts mentioned are both public so feel free to browse around the content if it helps you understand the concepts. 

I deploy to three free Azure Web Apps and I will keep them running for the time being. Usually I would use standard edition web apps and make use of slots, however the principle of deploying to a slot and a website is the same, you just need to tick the deploy to slot option.

To deploy to the Virtual Machine there is a bit more magic involved that is not mentioned in the video.  

The following powershell needs to be run as an administrator, this connects you VM to Azure DevOps and can be found in the Deployment Groups section of pipelines under register. 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/sfy6uw9d09ptyuzej70l.JPG)

<code>$ErrorActionPreference="Stop";If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole( [Security.Principal.WindowsBuiltInRole] “Administrator”)){ throw "Run command in an administrator PowerShell prompt"};If($PSVersionTable.PSVersion -lt (New-Object System.Version("3.0"))){ throw "The minimum version of Windows PowerShell that is required by the script (3.0) does not match the currently running version of Windows PowerShell." };If(-NOT (Test-Path $env:SystemDrive\'azagent')){mkdir $env:SystemDrive\'azagent'}; cd $env:SystemDrive\'azagent'; for($i=1; $i -lt 100; $i++){$destFolder="A"+$i.ToString();if(-NOT (Test-Path ($destFolder))){mkdir $destFolder;cd $destFolder;break;}}; $agentZip="$PWD\agent.zip";$DefaultProxy=[System.Net.WebRequest]::DefaultWebProxy;$securityProtocol=@();$securityProtocol+=[Net.ServicePointManager]::SecurityProtocol;$securityProtocol+=[Net.SecurityProtocolType]::Tls12;[Net.ServicePointManager]::SecurityProtocol=$securityProtocol;$WebClient=New-Object Net.WebClient; $Uri='https://vstsagentpackage.azureedge.net/agent/2.160.1/vsts-agent-win-x64-2.160.1.zip';if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))){$WebClient.Proxy= New-Object Net.WebProxy($DefaultProxy.GetProxy($Uri).OriginalString, $True);}; $WebClient.DownloadFile($Uri, $agentZip);Add-Type -AssemblyName System.IO.Compression.FileSystem;[System.IO.Compression.ZipFile]::ExtractToDirectory( $agentZip, "$PWD");.\config.cmd --deploymentgroup --deploymentgroupname "VM" --agent $env:COMPUTERNAME --runasservice --work '_work' --url 'https://dev.azure.com/azureadventcalendar/' --projectname 'AzureAdventCalendar'; Remove-Item $agentZip;</code>

That is all you need to do to your VM, you don't even need to install IIS, the deployment steps do that for you. I did need to manually install the [.net Core IIS module](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.0#install-the-net-core-hosting-bundle) because my code requires it.
 
The application I use in the video is based off the Blazor template that is part of Visual Studio 2019. Create a new Blazor applicaton and you should get a very similar application with a table of temperatures, and a counter. I tweaked this slightly to make it more Christmas themed. The snow is an old javascript file that i added to the page. If anyone knows how to do that in pure c# blazor I would love to know.

If you enjoyed this video let me know as I am considering recording some more in 2020 so watch this space!