0

I am trying to download the files related to ADO changeset into a folder.

By using below API I am able to retrieve the changeset:

GET https://dev.azure.com/{organization}/{project}/_apis/tfvc/changesets/{id}?api-version=5.1

I am writing a PS script something like this to download the files

$user = "XXXX"
$pass = "YYYYY"

$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"

$Headers = @{
    Authorization = $basicAuthValue
}

Invoke-WebRequest -Uri GET https://dev.azure.com/{organization}/{project}/_apis/tfvc/changesets/{id}?api-version=5.1 -Headers $Headers 

By using the above script I am able to retrieve the changes associated with changeset but how to download the files related to that changeset into a folder.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • Any update for this issue? Have you resolved this issue? If not, would you please let me know the latest information about this issue? – Joy May 19 '20 at 09:56

1 Answers1

0

You can use the Changesets - Get Changeset Changes API to get the files list of the changeset:

GET https://dev.azure.com/{organization}/_apis/tfvc/changesets/{id}/changes?api-version=5.1

Then iterate the results ans use the Items - Get API to download the item.

GET https://dev.azure.com/{organization}/{project}/_apis/tfvc/items?path={path}&api-version=5.1

P.S. Better to use Invoke-RestMethod instead of Invoke-WebRequest.

Example to a working script:

$user = "XXXX"
$pass = "YYYYY"

$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"

$Headers = @{
    Authorization = $basicAuthValue
}

$cs = Invoke-RestMethod -Uri "https://dev.azure.com/{organization}/_apis/tfvc/changesets/{id}/changes?api-version=5.1" -Headers $Headers 

$cs.value.ForEach({

$url = "https://dev.azure.com/{organization}/{project}/_apis/tfvc/items?path=$($_.item.path)&api-version=5.1"
$name = $cs.value[0].item.path.Split('/')[$cs.value[0].item.path.Split('/').count -1]
Invoke-RestMethod -Uri $url -ContentType application/octet-stream -Headers $Headers  | Out-File C:\Files\$name

})
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114