TFS非活动项目列表

时间:2018-01-02 16:25:08

标签: tfs

我有一堆项目的TFS服务器,我需要知道哪些项目正在被使用,所以我可以删除不再开发的项目。

我想使用TFS2018 api来做到这一点。

  1. 获取过去一年积极开展工作的项目清单的最佳方法是什么?

  2. 获取过去一年建成的项目清单的最佳方法是什么?

  3. 谢谢!

1 个答案:

答案 0 :(得分:0)

通常我们无法直接使用API​​实现这一点,因为项目没有明确的状态来识别项目是处于活动状态还是非活动状态。我们可以看到项目的状态都是“wellFormed”。见Get a list of team projects

但是,您可以使用Workitems尝试API。基本上,如果所有相关工作项都完成,则项目应处于非活动状态。

下面的PS脚本示例参考,使用REST API检索具有完成工作项计数的项目。 ( 0 表示无效

Param(
   [string]$collectionurl = "http://server:8080/tfs/DefaultCollection",
   [string]$keepForever = "true",
   [string]$user = "username",
   [string]$token = "password"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$projecturi = "$($collectionurl)/_apis/projects?api-version=1.0"
$projects = (Invoke-RestMethod -Uri $projecturi -Method Get -UseDefaultCredential).value.name


foreach ($project in $projects)

{

    function CreateJsonBody
  {

    $value = @"
    {
      "query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [State] <> 'Done' AND [System.TeamProject]='$project' AND [System.ChangedDate] < '2018-01-01' AND [System.ChangedDate] > '2017-01-01' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
    }
"@

   return $value
  }

$json = CreateJsonBody

$uri = "$($collectionurl)/_apis/wit/wiql?api-version=1.0"
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

write-host "ProjectName:" $project : $result.workItems.Count
}

enter image description here

相关问题