Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Last active May 12, 2018 15:41
Show Gist options
  • Save IlyaFinkelshteyn/8c1fac29c0386f06064659b562e53774 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/8c1fac29c0386f06064659b562e53774 to your computer and use it in GitHub Desktop.
$username = "token"
$password = "<VSTS_Token>"
$account = "<VSTS_account_name>"
$project = "<VSTS_project_name>"
$repository = "<VSTS_repository_name>"
$commitId = "<VSTS_commit_id >"
$b = [System.Text.Encoding]::ASCII.GetBytes($username + ":" + $password)
$p = [System.Convert]::ToBase64String($b)
$client = New-Object Net.WebClient
$client.Headers.Add("Accept", "application/zip")
$client.Headers.Add("Authorization", "Basic $p")
$zipPath = "$($env:TEMP)\$project.zip"
Add-Type -AssemblyName System.Web
$url = "https://$account.visualstudio.com/DefaultCollection/_apis/git/$project/repositories/$repository/items?scopePath=$([System.Web.HttpUtility]::UrlDecode("/"))&versionType=commit&version=$commitId"
$client.DownloadFile($url, $zipPath)
# this part is needed if using as AppVeyor build clone script
# not needed for local repro
7z x $zipPath -aoa -o"$env:TEMP" | Out-Null
$buildFolderRoot = $env:APPVEYOR_BUILD_FOLDER.Substring(0, $env:APPVEYOR_BUILD_FOLDER.LastIndexOf("\"))
move $env:TEMP\$\$project $buildFolderRoot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment