我正在使用VS 2013与Team Explorer链接到Visual Studio Online。
我有“发布”构建定义,我想将其复制/克隆到“debug”构建的新定义。
团队资源管理器似乎没有给我这个选项: - (
我尝试使用“社区TFS构建管理器”来克隆构建定义,但似乎不允许这样做,因为它需要克隆到不同的项目。
我尝试使用TFS Power工具TFPT powershell命令,但它总是给我一个错误“无法确定源控制服务器”。
制作构建定义副本的推荐方法是什么?
答案 0 :(得分:3)
转到团队资源管理器。
选择要克隆的特定构建。
右键单击 - >克隆构建定义。
通过这种方式,您可以克隆Build定义,该定义将保存在名称为
的同一项目下[您选择的构建定义] 的副本。
答案 1 :(得分:1)
如果您希望使用Powershell在VSTS中自动克隆构建,则可以使用以下脚本(与此documentation一致)。
您需要更改:
$buildToCloneName
,$newBuildName
,$user
,$accessToken
,$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI
和$env:SYSTEM_TEAMPROJECTID
让它为您效劳。
$env:SYSTEM_TEAMPROJECTID
是构建所在的团队项目。
Powershell脚本:
Clear-Host
$buildToCloneName = "Build 1"
$newBuildName = "Build 1 - Clone"
$user = "myname@mycompany.com"
$accessToken="4df31252fqt...PAT...."
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$accessToken)))
$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = "https://mycompany.visualstudio.com/"
$env:SYSTEM_TEAMPROJECTID = "MyProject"
"Getting all bulid definitions"
$allSuitesBuildUrl = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$($env:SYSTEM_TEAMPROJECTID)/_apis/build/definitions?api-version=2.0"
$allSuitedBuilds = Invoke-RestMethod -Uri $allSuitesBuildUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
"Builds Found - Finding Match for $buildToCloneName"
$buildWeWant = {}
foreach($buildDetails in $allSuitedBuilds.value)
{
"Checking Build"
$buildDetails."name"
if($buildDetails."name" -like $buildToCloneName)
{
$xoutputname = $buildDetails."name"
"YES! Got Build $xoutputname"
$buildWeWant = $buildDetails
break
}
else
{
"Nope!"
}
}
$buildId = $buildWeWant."id"
[int]$buildIdTest = $null
if(![int]::TryParse($buildId, [ref]$buildIdTest))
{
throw [Exception] "ERROR: NO BUILD ID FOUND"
}
"Getting the exact definition for the build"
# You can see this in the browser using https://mycompany.visualstudio.com/ProjectWhereBuildIs/_apis/build/definitions/{BuildNumber}?api-version=2.0
$thisBuildDefUrl = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$($env:SYSTEM_TEAMPROJECTID)/_apis/build/definitions/" + $buildId + "?api-version=2.0"
$thisBuildDefUrl
$thisBuildDef = Invoke-RestMethod -Uri $thisBuildDefUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
"Assigning a new name"
$thisBuildDef.Name = $newBuildName
"Creating a clone build with name $newBuildName"
$defAsJson = $thisBuildDef | ConvertTo-Json -Depth 100
$newBuildDefUrl = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$($env:SYSTEM_TEAMPROJECTID)/_apis/build/definitions?api-version=2.0"
$newBuildDef = Invoke-RestMethod -Uri $thisBuildDefUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Post -Body $defAsJson -ContentType "application/json" -ErrorAction Stop
$newBuildDefAsJson = $newBuildDef | ConvertTo-Json -Depth 100
$newBuildDefAsJson
"New Build Created"
$newBuildDef.Name
答案 2 :(得分:1)