This blog post is part of Azure Advent Calendar do check out some of the other videos and blog posts. The YouTube channel can be found here
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.
The Github and Azure DevOps 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.
$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;
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 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!