【问题标题】:Is it possible to initiate a TFS build from one collection to another?是否可以从一个集合启动 TFS 构建到另一个集合?
【发布时间】:2018-12-11 01:11:59
【问题描述】:

我正在寻找一种方法,允许一个构建启动另一个集合中的另一个构建。如果可能的话,有没有办法让它等到构建完成后再继续?

【问题讨论】:

  • 当然。你用的是什么版本?您看过 REST API 吗?
  • @Daniel Mann 我正在使用 TFS 2017
  • 好的。您看过 REST API 文档吗?您可以轻松地编写脚本来涵盖这种情况,并且 API 的文档非常完善。如果您在使用 REST API 时遇到问题,可以提出相关问题。
  • @KevinCraft 只需在构建定义中添加一个PowerShell 任务作为last 任务,然后在下面的Shayki Abramczyk's 答案中运行脚本。
  • @KevinCraft 你解决了这个问题吗?有更新吗?

标签: c# visual-studio tfs collections build


【解决方案1】:

您可以运行触发其他构建的 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" -Credentials "domain\user:MyP@ssw0rd"

您可以很好地here 如何在 TFS 上使用 Powershell 任务。

【讨论】:

    猜你喜欢
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-28
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多