我正试图下载ADO变化集的相关文件到一个文件夹中。
通过使用下面的API,我能够检索到变化集。
GET https://dev.azure.com/{organization}/{project}/_apis/tfvc/changesets/{id}?api-version=5.1
我写了一个类似于这样的PS脚本来下载文件。
$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
通过使用上面的脚本,我能够检索与变化集相关的变化,但如何下载与变化集相关的文件到一个文件夹中。
你可以使用 变更集 - 获取变更集变更 API来获取变化集的文件列表。
GET https://dev.azure.com/{organization}/_apis/tfvc/changesets/{id}/changes?api-version=5.1
然后对结果进行迭代,并使用 项目 - 获取 下载项目的API。
GET https:/dev.azure.com。{organization}{project}_apistfvcitems?path={path}&api-version=5.1。
P.S. 最好使用 Invoke-RestMethod
而不是 Invoke-WebRequest
.
例子到工作脚本。
$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
})