How to deploy Azure Pipelines agent?

Scripts

“parameters”: {
“adminUsername”: {
“value”: “test-user”
},
“adminPassword”: {
“value”: “test-P@ssw0rd12345”
},
“vmName”: {
“value”: “ado-agents”
},
“AccessIPNSG”: {
“value”: “192.168.1.1”
},
“tag”: {
“value”: “AzureDevOpsAgent”
},
“DiskForVM”: {
“value”: “StorageAccount”
}
}

“parameters”: {
“ResourceGroupLocation”: {
“value”: “westeurope”
},
“ResourceGroupName”: {
“value”: “vm-azure-devops-self-hosted-agents”
},
“tag”: {
“value”: {
“key1”: “Project”,
“value1”: “AzureDevOpsAgent”
}
}
}

param(
[Parameter(Mandatory = $true)][string] $urlProjectADO,
[Parameter(Mandatory = $false)][string] $auth = “pat”,
[Parameter(Mandatory = $true)][string] $token,
[Parameter(Mandatory = $false)][string] $pool,
[Parameter(Mandatory = $false)][string] $agentname,
[Parameter(Mandatory = $false)][ValidateRange(1, 20)][int] $numberagents = 1,
[Parameter(Mandatory = $false)][bool] $instalAddtionalPackages = $true
)
begin {
}
process {
try {
if (!(Test-Path “c:\temp”)) { $null = mkdir “c:\temp” }
$log | % {
# Install Additional Packages
if ($instalAddtionalPackages) {
try {

# Install Packages
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name “Nuget” -Force
# FIX: WARNING: Not setting tab completion: Profile file does not exist at ‘C:\Users\USER\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1’.
if (!(Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))
choco feature enable -n allowGlobalConfirmation
choco install -y powershell-core
Start-Sleep 3
choco install -y azure-cli
Start-Sleep 3
choco install -y az.powershell
Start-Sleep 3
choco install -y azcopy
Start-Sleep 3
choco install -y iiscrypto
Start-Sleep 3
#Install AzureRM in Powershell 5.1
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Command “Install-Module -Name AzureRM -AllowClobber -Force -Confirm:`$false”
# END Install Packages

}
catch {
throw $_
break
}
}
# Get latest version install agent
$getLatestVersion = Invoke-WebRequest https://api.github.com/repos/Microsoft/azure-pipelines-agent/releases/latest -UseBasicParsing
$tag = ($getLatestVersion | ConvertFrom-Json)[0].tag_name
$tag = $tag.Substring(1)
$downloadInstallURL = “https://vstsagentpackage.azureedge.net/agent/$tag/vsts-agent-win-x64-$tag.zip"

# Creating Pool in Azure DevOps
$encodedPat = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes( “:$token”))
$body = “{name:`”$pool`”, autoProvision: `”true`”}”
if (!($pool -match “default” -or $pool -match “Azure Pipelines” -or $((Invoke-WebRequest -Method GET -Uri “$urlProjectADO/_apis/distributedtask/pools?api-version=5.1” -UseBasicParsing -Headers @{Authorization = “Basic $encodedPat” }).content | ? { $_ -like “*$pool*” }))) {
$tmp = $(Invoke-WebRequest -Method POST -Uri “$urlProjectADO/_apis/distributedtask/pools?api-version=5.0-preview.1” -UseBasicParsing -Headers @{Authorization = “Basic $encodedPat” } -Body $body -ContentType “application/json”) 2>$null
}

# Install agents
$filename = $urlProjectADO.Split(‘/’)[-1]
if (!(Test-Path “c:\temp\$filename”)) { Invoke-WebRequest -Uri $downloadInstallURL -OutFile “c:\temp\$filename” }

for ($i = 1; $i -le $numberagents; $i++) {
if (!(Test-Path “c:\agent-$i”)) { mkdir “c:\agent-$i” }else { rm c:\agent-$i -recurse -force; mkdir “c:\agent-$i” }
Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory(“c:\temp\$filename”, “c:\agent-$i”)
.”c:\agent-$i\config.cmd” — unattended — url $urlProjectADO — auth $auth — token $token — pool $pool — agent “$agentname-$i” — runAsService
}
} | Out-File “c:\temp\ADOagent-$((Get-Date).ToString(“s”).Replace(“:”,”-”)).log”
Remove-Item -Recurse -Force c:\temp -Exclude *.log
}
catch {
throw $_
break
}
Write-Verbose “Successfully installed Azure DevOps Job Agents”
}

After deployment:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store