PowerShell your DevOps environment - Part 2

A picture



Reading time

3 minutes


In this blog post, we are going to look at automated application deployment to VMs using continuous deployment in Azure DevOps.

Read part 1 here.

Azure DevOps Services is a rebranded product that used to be called Microsoft Studio Online or Visual Studio Team Services (VSTS) in the early days. You still can see the URL redirection, which links to https://app.vssps.visualstudio.com and then redirects to https://dev.azure.com/.

Azure DevOps provides a range of services, but we are currently only using four of them:

  • Repos
  • Pipelines
  • Test Plans
  • Artifacts

Repos provides the repositories for your Azure DevOps projects. You can import the project artifacts in Visual Studio Code, for example, or other editors.

Pipelines creates your workflow of software builds and releases, connections to targets and pre and post-requirements. You can pull your packages from Github or other repositories.

Test Plans lets you do various test runs and analyse the logs and different errors during your deployment.

Artifacts enables you to share your packages on different platforms.

In order to deploy a software package, you need a deployment group connected to the project. Microsoft Azure lets you deploy different groups and install a target agent to connect the VMs to your project in Azure DevOps Services.

You can create different pools of existing VMs or deploy a new VM pool with ARM services in Microsoft Azure. But either way you need to install the target agent, which can be installed on Microsoft Windows or Linux OS. First, you need to allow the ARM outputs extension to be installed in your Azure DevOps account.

A picture

  $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.155.1/vsts-agent-win-x64-2.155.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 "DG01" --agent $env:COMPUTERNAME --runasservice --work '_work' --url 'https://dev.azure.com/****/' --projectname 'Test'; Remove-Item $agentZip;

When that is done, you can copy the command and run the following PowerShell command in Windows VMs manually or automatically.

You’re now ready to create, test, deploy and edit the different builds of your software with Microsoft Azure DevOps CI/CD solution. If you want to have a test run and see how it works with Azure DevOps Services, you can use predefined software package templates with Azure DevOps Generator. Here’s the link: https://azuredevopsdemogenerator.azurewebsites.net/environment/createproject

Read the first part of this blogpost here.

Blijf op de hoogte met Craft

Wil jij geen events meer missen en via blogs op de hoogte blijven van alle ontwikkelingen rondom Cloud? Meld je dan aan voor de Craft-update!