ADO API 使用更改集编号下载文件
ADO API to download the files using change set number
我正在尝试将与 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
通过使用上述脚本,我能够检索与变更集关联的变更,但如何将与该变更集相关的文件下载到文件夹中。
您可以使用 Changesets - Get Changeset Changes API 获取变更集的文件列表:
GET https://dev.azure.com/{organization}/_apis/tfvc/changesets/{id}/changes?api-version=5.1
然后迭代结果并使用 Items - Get API 下载项目。
GET https://dev.azure.com/{organization}/{project}/_apis/tfvc/items?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
})
我正在尝试将与 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
通过使用上述脚本,我能够检索与变更集关联的变更,但如何将与该变更集相关的文件下载到文件夹中。
您可以使用 Changesets - Get Changeset Changes API 获取变更集的文件列表:
GET https://dev.azure.com/{organization}/_apis/tfvc/changesets/{id}/changes?api-version=5.1
然后迭代结果并使用 Items - Get API 下载项目。
GET https://dev.azure.com/{organization}/{project}/_apis/tfvc/items?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
})