Last active
February 20, 2024 07:02
-
-
Save MaxMelcher/fa10b8bd7f1e39910c0402576ccf1b1f to your computer and use it in GitHub Desktop.
Powershell to install the latest Azure DevOps Agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$URL, | |
[string]$PAT, | |
[string]$POOL, | |
[string]$AGENT | |
) | |
Write-Host "start" | |
if (test-path "c:\agent") | |
{ | |
Remove-Item -Path "c:\agent" -Force -Confirm:$false -Recurse | |
} | |
new-item -ItemType Directory -Force -Path "c:\agent" | |
set-location "c:\agent" | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
$wr = Invoke-WebRequest https://api.github.com/repos/Microsoft/azure-pipelines-agent/releases/latest | |
$tag = ($wr | ConvertFrom-Json)[0].tag_name | |
$tag = $tag.Substring(1) | |
write-host "$tag is the latest version" | |
$url = "https://vstsagentpackage.azureedge.net/agent/$tag/vsts-agent-win-x64-$tag.zip" | |
Invoke-WebRequest $url -Out agent.zip | |
Expand-Archive -Path agent.zip -DestinationPath $PWD | |
.\config.cmd --unattended --url $URL --auth pat --token $PAT --pool $POOL --agent $AGENT --acceptTeeEula --runAsService | |
exit 0 |
Thanks for the script.
If you use Azure Custom Script Extension it is necessary to use -UseBasicParsing parameter
$wr = Invoke-WebRequest -Uri "https://api.github.com/repos/Microsoft/azure-pipelines-agent/releases/latest" -UseBasicParsing
More info: MicrosoftDocs/azure-docs#14377
https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows#using-invoke-webrequest
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is so incredibly helpful! Thank you for sharing - this has probably saved me hours of work.