TFS API - minTime过滤器无法正常工作

时间:2018-05-26 14:41:40

标签: api tfs tfs2017

是否存在minTime参数工作所需的API版本级别?

GET https://{accountName}.visualstudio.com/{project}/_apis/build/builds?api-version=3.1&minTime=?????

我们在内部运行TFS api ver 3.1并且minTime似乎对我们不起作用。

很高兴知道什么参数可用于什么api版本。

文档说4.1支持这个参数:

maxTime query       
string
date-time   
If specified, filters to builds that finished/started/queued before this date based on the queryOrder specified.

minTime query       
string
date-time   
If specified, filters to builds that finished/started/queued after this date based on the queryOrder specified.

1 个答案:

答案 0 :(得分:1)

是的,minTime支持maxTimeapi-version=4.1参数。

有关详细信息,请参阅REST API:Builds - List。它提到了api-version=4.1所有可用的URI Parameters

在您的方案中, TFS 2017不支持api-version=4.1 。它仅支持api ver 3.xx和早期版本(1.02.0)。有关详细信息,请参阅REST API Versioning-Supported versions

因此,如果您想使用minTimemaxTime参数,可以升级到TFS 2018或迁移到VSTS。

或者,您可以使用其他工具按日期过滤构建,例如,您可以通过调用REST API在PowerShell中进行过滤。

Param(
   [string]$baseurl = "http://server:8080/tfs/DefaultCollection",  
   [string]$projectName = "ProjectName",
   [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)))

$uri = "$baseurl/$($projectName)/_apis/build/builds"

$result = Invoke-RestMethod -Uri $uri -Method GET  -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

$builds = $result.value | Where {$_.finishTime -ge '2018-05-24' -and $_.finishTime -le '2018-05-29'} # Filter builds by finish time between '2018-05-24' and '2018-05-29'

enter image description here