我需要PowerShell脚本来获得成功构建的构建质量(已发布或已拒绝或试用版)。
尝试使用以下脚本:问题是如果我有超过4-5个版本的构建,我如何获得构建列表????下面的脚本为我提供了关于更改MaxBuildsPerDefinition = 2或3的值的建议。我需要获得所有候选版本。
[string] $tfsLocation = "http://serverURL/tfs"
[string] $projectName = "ProjectName"
[string] $buildDefinitionName = "BuildDefinition"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.Build.Client.dll"
$tfsUri = New-object Uri($tfsLocation)
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsUri)
$service = $teamProjectCollection.GetService([Type]"Microsoft.TeamFoundation.Build.Client.IBuildServer")
$spec = $service.CreateBuildDetailSpec($projectName, $buildDefinitionName)
$spec.MaxBuildsPerDefinition = 2
$spec.QueryOrder = [Microsoft.TeamFoundation.Build.Client.BuildQueryOrder]::FinishTimeDescending
$results = $service.QueryBuilds($spec)
if ($results.Builds.Length -eq 2)
{
Write-Host $results.Builds[0].Quality
if ($results.Builds[0].Quality = "Released")
{
<<My Script Here>>
} else {
<<My Script Here>>
}
} else {
Write-Error "No builds found."
}
答案 0 :(得分:0)
您可以尝试使用REST API来检索成功构建的构建质量。您可以根据您的要求相应地指定过滤器。您还可以将构建列表导出到 .CSV 文件。
$collectionurl = "http://serverURL/tfs"
$projectName= "ProjectNname"
$BuildDefinitionId = "74"
$baseUrl = "$collectionurl/$projectName/_apis/build/builds?api-version=2.0&definitions=$BuildDefinitionId&statusFilter=completed&resultFilter=succeeded" # Set the filter based on your requirements.
$builds = (Invoke-RestMethod -Uri $baseUrl -Method Get -UseDefaultCredential).value|where({$_.quality -in 'Released', 'Rejected','Trial'}) # filter the builds which have quality elements.
$BuildResults = @()
foreach($build in $builds){
$customObject = new-object PSObject -property @{
"BuildDefinition" = $build.definition.name
"BuildId" = $build.id
"BuildNumber" = $build.buildNumber
"status" = $build.status
"result" = $build.result
"BuildQuality" = $build.quality
"finishTime" = $build.finishTime
"sourceBranch" = $build.sourceBranch
}
$BuildResults += $customObject
}
$BuildResults | Select `
BuildDefinition,
BuildId,
BuildNumber,
status,
result,
BuildQuality,
finishTime,
sourceBranch #|export-csv -Path E:\$projectName-Build.csv -NoTypeInformation