从powershell重试以前运行的TFS构建

时间:2016-01-14 00:55:20

标签: powershell tfs build

我试图以编程方式重试以前完成的TFS构建。 (就像你可以通过"动作,重试构建"来完成VS.)

下面的示例PS代码连接到TSF,通过其ID获取先前构建的构建队列,并尝试设置其重试状态并保存。保存失败,说构建状态需要"已完成。"查询状态显示"已完成"。

. ".\loadTfsAssemlies.ps1"

$tfsURL = "http://myServer:8080/tfs/myCollection"
$tpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsURL)
$bs = $tpc.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$qb = $bs.getqueuedbuild(258498,"All")

$qb.retry()
$qb.save()

Exception calling "Save" with "0" argument(s): "Queued build 258498 on build controller blah blah can only be retried if the status is Completed. The status was Completed."
At line:1 char:1
+ $qb.save()
+ ~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : QueuedBuildUpdateException

 $qb.status
Completed

我在这里做错了什么想法?或者可能知道重试之前构建的更好方法?

1 个答案:

答案 0 :(得分:0)

检查$qb.retry(); $qb.Save()发送的请求与右键单击重试Visual Studio之间的差异后,我发现调用需要:

qb.Retry([Guid]::NewGuid(), "Completed")
qb.Save()

retryOption需要明确传递为Completed,或者默认为InProgress