Search code examples
azure-devopsazure-devops-rest-apiazure-devops-server

Azure DevOps Server local install Extension over REST API


The article Install Extension By Name describe how to install a extension from the marketplace by its name.

Is it also possible to install a extension locally to a Azure DevOps Server?

  1. Step: server_ip/_gallery/manage

  2. Step: Upload

enter image description here

  1. Step: Install

enter image description here

It would be great to make these steps programmatically.


Solution

  • PowerShell Script for add or delete a Extension based on a .vsix file to a Azure DevOps Server extension gallery:

    $PAT = "PersonalAccessToken"
    $Uri = "http://ip:port"
    $timeout = 30
    
    #AUTHORIZATION HEADERS
    $headers = @{
        "Authorization" = ('Basic {0}' -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)")))
        "If-Match"      = ""
    }
    
    #VARIABLE
    $publisher = "YourPublisherName"
    $extension = "YourExtensionName"
    $vsix = "YourVsixPath.vsix"
    
    #DELETE EXTENSION
    $api = "api-version=5.0-preview.2"
    $url = "$Uri/_apis/gallery/publishers/$publisher/extensions/$($extension)?$api"
    $result = Invoke-RestMethod -Uri $url -Method DELETE -ContentType "application/json" -Headers $headers -TimeoutSec $timeout -Verbose
    Write-Host $result
    
    #ADD EXTENSION
    $api = "api-version=3.0-preview.1"
    $body = '{{"extensionManifest": "{0}"}}' -f ([Convert]::ToBase64String([IO.File]::ReadAllBytes($vsix)))
    $url = "$Uri/_apis/gallery/extensions?$api"
    $result = Invoke-RestMethod -Uri $url -Method POST -ContentType "application/json" -Headers $headers -Body $body -TimeoutSec $timeout -Verbose
    Write-Host $result