Search code examples
azure-devopsazure-rm-templateazure-devops-extensions

Install extensions when creating VSTS account with ARM template


I'm using powershell and an ARM template to create a new Team Services account + DevOps Project. Template type: microsoft.visualstudio/account

Is there a way to also install extensions via the template or powershell?

I have a couple of extensions I'm always using, It would be nice to automatically have them up and running on new projects.


Solution

  • If anybody stumbles upon this same problem, here's how you can do it with powershell.
    After creating the VSTS account, you need to log in and create a personal access token with Extensions (read and manage) in selected scopes.

    $accountName = "yourAccount"
    $personalAccessToken = "your-personal-access-token"
    
    $uri = "https://" + $accountName + ".extmgmt.visualstudio.com/_apis/extensionmanagement/installedextensionsbyname/ms-appinsights/appinsightsreleaseannotations?api-version=5.0-preview.1"
    
    Write-Host "Installing extension: Release Annotations for Azure Application Insights"
    Invoke-RestMethod `
    -Method Post `
    -Uri $uri `
    -ContentType application/json `
    -Headers @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)")) }