1

I would like to download an application from azure devops repository via command line (like using powershell) peridiocally but i can not use git plugin for that. IS there any way besides git to do that?

Matt
  • 3,658
  • 3
  • 14
  • 27
blst
  • 25
  • 1
  • 6

3 Answers3

2

You can download files from Git repository with Azure DevOps Rest API - Items - Get (without git plugin).

https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&api-version=5.0-preview.1

If you add the parameter download (for example: ?path={path}&download=true) the file will be downloaded.

So you can get the file with PowerShell script:

Param(
   [string]$organization= "<Organization-NAME>",
   [string]$projectName = "<PROJECT-NAME>",
   [string]$repoId= "<Repository-ID>",
   [string]$appPath= "<Application-Path>",
   [string]$user = "",
   [string]$token = "<PERSONAL-ACCESS-TOKEN>"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$uri = "https://dev.azure.com/$($organization)/$($project)/_apis/git/repositories/$($repoId)/items?path=$($appPath)&download=true&api-version=5.0-preview.1"

$result = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
0

Best and easiest option for this :

Step 1: Set up a VSTS Agent. Step 2: Create a build pipeline (used be called definition until just recently)

Let me know if you need any help on this.

In case if you only want to use command line tool then you can refer-

https://blog.rsuter.com/script-to-clone-all-git-repositories-from-your-vsts-collection/

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27
0

Thanks guys, I resolved this with small changes, instead of using git in url, i changed the $uri parameter to:

$uri = "<Azure URL>/<RepoID>/_apis/tfvc/Items?path=<ApplicationPath>&versionDescriptor%5BversionType%5D=5&%24format=zip&api-version=4.1-preview.1"
blst
  • 25
  • 1
  • 6