团队基础服务器如何为特定项目提取禁用的构建定义

时间:2017-06-18 17:04:28

标签: powershell tfs build

我在TFS中有很多构建def,我尝试仅使用 MMD _ 项目来获取已禁用的构建定义。



$baseUrl = "https://tfs.myTFS.net/tfs"
$targetCollection = "DefaultCollection"
$targetProject = "MMD"
# Get an overview of all build definitions in this team project
$definitionsOverviewUrl = "$baseUrl/$targetCollection/$targetProject/_apis/build/Definitions"
$definitionsOverviewResponse = Invoke-WebRequest -UseDefaultCredentials -Uri $definitionsOverviewUrl
$definitionsOverview = (ConvertFrom-Json $definitionsOverviewResponse.Content).value
# Process all builds that have MMD in their name and want only disabled build def seperated from MMD_
foreach($definitionEntry in ($definitionsOverview | Where-Object { $_.name -like '*MMD_*' }))
{
    $definitionUrl = $definitionEntry.url
    $response = Invoke-WebRequest $buildDefinitionUrl -UseDefaultCredentials
    $buildDefinition = [Newtonsoft.Json.JsonConvert]::DeserializeObject($response.Content)
 #check whether source settings are null or not 
	if(!$buildDefinition.enabled)
    {
        Write-Output $definitionsOverview + 'build definition is disabled'
		# I need process parameter is 
    }
}




1 个答案:

答案 0 :(得分:0)

我假设您正在尝试查询XAML构建定义,因为禁用构建定义选项仅在XAML构建系统中可用。请确保您使用Build API 1.0,因为API 2.0适用于新的vNext构建系统。因此,在$definitionsOverviewUrl中添加?api-version=1.0

当构建定义为“已禁用”或“已暂停”时,构建定义状态将保存在“queueStatus”属性中。如果启用了构建定义,则不会有“queueStatus”属性。因此,您需要相应地更新代码。 enter image description here