是否可以启动从一个集合到另一个集合的TFS构建?

时间:2018-07-02 19:11:55

标签: c# visual-studio tfs collections build

我正在寻找一种方法,以允许一个版本开始其他系列中的另一个版本。如果可以的话,有没有办法等到构建完成后再继续?

1 个答案:

答案 0 :(得分:0)

您可以运行触发其他构建的Powershell脚本:

param
(
    [Parameter(Mandatory=$true)]
    $BuildDefinitionId,
    [Parameter(Mandatory=$true)]
    $CollectionUrl,
    [Parameter(Mandatory=$true)]
    $TeamProject,
    [Parameter(Mandatory=$true)]
    $Credentials
)

try
{
    $apiVersion = "2.0"
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}" -f $Credentials)))
    $body = @{ definition = @{id = $BuildDefinitionId} }
    $requestUrl = "$CollectionUrl/$TeamProject/_apis/build/builds" + "?api-version=$apiVersion"
    $response = Invoke-RestMethod -Method Post -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType application/json -Uri $requestUrl -Body (ConvertTo-Json $body)
    return $response
}

catch
{
    Write-Host "Failed to trigger build {$BuildDefinitionId}, Exception: $_" -ForegroundColor Red
    return $null
}

}

参数示例:

  

-BuildDefinitionId“ 37” -CollectionUrl“ http://tfsserver:8080/tfs/DefaultCollection” -TeamProject“ MyProject”-凭据“ domain \ user:MyP @ ssw0rd”

您可以完善here如何在TFS上使用Powershell任务。