Azure devops VS团队服务上的备份工作项
是否可以以某种方式备份/导出/下载所有工作项?我看了一下REST API,但是看起来你不能通过这个API执行F.E.查询…< P>你可以使用Team Foundation Advin到Excel导出工作项查询到Excel,如描述的 < P> OK,找到了一种完成任务的方法。我又看了一遍API文档。这一页帮了我的忙。你首先需要做一个测试Azure devops VS团队服务上的备份工作项,azure-devops,tfs-sdk,azure-devops-rest-api,Azure Devops,Tfs Sdk,Azure Devops Rest Api,是否可以以某种方式备份/导出/下载所有工作项?我看了一下REST API,但是看起来你不能通过这个API执行F.E.查询…< P>你可以使用Team Foundation Advin到Excel导出工作项查询到Excel,如描述的 < P> OK,找到了一种完成任务的方法。我又看了一遍API文档。这一页帮了我的忙。你首先需要做一个测试 GET https://{account}.visualstudio.com/defaultcollection/{project}/_apis/wit/quer
GET https://{account}.visualstudio.com/defaultcollection/{project}/_apis/wit/queries/{folderpath}?api-version={version}&$expand=wiql
POST https://{account}.visualstudio.com/defaultcollection/{project}/_apis/wit/wiql?api-version={version}
从生成的JSON中,您需要获得wiql部分,这是实际的查询。在这之后,你需要做一个
GET https://{account}.visualstudio.com/defaultcollection/{project}/_apis/wit/queries/{folderpath}?api-version={version}&$expand=wiql
POST https://{account}.visualstudio.com/defaultcollection/{project}/_apis/wit/wiql?api-version={version}
其中主体是JSON,带有{“query”=“YOURQUERY”}
因此,您将收到一个包含所有工作项URL/ID的JSON。您需要遍历它们并通过查询每个工作项
GET URL?$expand=all
注意:仅当您还需要关系和附件时,才添加?$expand=all。
我在PowerShell里放了些东西。注意:我决定对查询进行硬编码,并删除错误处理,使其变得更短
function loadJsonFile($fileName)
{
return ConvertFrom-Json "$(Get-Content $fileName)"
}
function getLastItemFromURL($url)
{
$absPath = ([System.Uri]$url).AbsolutePath
$lastSlash = $absPath.LastIndexOf("/")
$absPath.Substring($lastSlash+1)
}
function getWorkItemId($url)
{
getLastItemFromURL($url)
}
# make sure you enabled alternative credentials and access for them
# you can get the value for YOURCODE i.e. via Fiddler
$headers = @{Authorization="Basic YOURCODE"}
# before this you would need to find the WIQL of the query; left to you
$body = @{
"query" = "THEQUERYFROMTHEJSON"
}
$bodyJson = $body | ConvertTo-Json
Invoke-RestMethod -method Post -ContentType application/json -Uri "https://{account}.visualstudio.com/defaultcollection/{project}/_apis/wit/wiql?api-version=1.0" -Headers $headers -Body $bodyJson -OutFile workitems.json
$workItemsJson = $(loadJsonFile workitems.json)
$workItems = $(foreach ($relation in $workItemsJson.workItemRelations)
{
$relation.target.url
$relation.source.url
}) | select -Unique | sort
echo "Going to download the following ids from $(getWorkItemId $workItems[0])-$(getWorkItemId $workItems[-1])"
# download the workitems
foreach($workItemUrl in $workItems)
{
$workItemId = getWorkItemId $workItemUrl
echo "Download ID: $workItemId"
$workItemUrl = "$workItemUrl`?`$expand=all"
$fileName = "workitem_$workItemId.json"
Invoke-RestMethod -ContentType application/json -Uri "$workItemUrl" -Headers $headers -OutFile "$fileName"
# download attachments
$workItemJson = $(loadJsonFile "$fileName")
foreach($relation in $workItemJson.relations)
{
if($relation.rel -eq "AttachedFile")
{
$fileUrl = $relation.url
Invoke-WebRequest $fileUrl -Headers $headers -OutFile $(getLastItemFromURL $fileUrl)
}
}
}
我需要一些可以在powershell脚本中执行的东西。最好不安装Excel。