我通过在每个成功的构建中创建一个分支来解决这个问题(不是最好的方法,但不是CI,我们没有很多构建)。
因为
tf barnch
Param(
[string]$path
)
$newCodeFolderPath = "$($env:Agent_BuildDirectory)\newCode"
$tempWorkspacePath = "$($env:Agent_BuildDirectory)\tempWorkspace"
New-Item -Path $newCodeFolderPath -ItemType directory
Copy-Item -Path "$($env:Build_SourcesDirectory)/*" -Recurse -Destination $newCodeFolderPath
New-Item -Path $tempWorkspacePath -ItemType directory
cd $tempWorkspacePath
$tfExe = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe"
& $tfExe workspace /collection:{TfsCollection} /new "TempWorkspace" /noprompt
& $tfExe workfold "$($path)/Release/$($env:Build_BuildNumber)" $tempWorkspacePath
Copy-Item -Path "$($newCodeFolderPath)/*" -Recurse -Destination $tempWorkspacePath
& $tfExe add * /recursive /noignore
& $tfExe checkin /recursive /comment:"from vNext build"
& $tfExe workspace /delete /collection:{TfsCollection} "Tempworkspace"
cd c:/
Remove-Item -Path $newCodeFolderPath -Force -Recurse
Remove-Item -Path $tempWorkspacePath -Force -Recurse
$releaseBranchPath = "$($path)/Release/$($env:Build_BuildNumber)
Write-Host ("##vso[task.setvariable variable=releaseBranchPath;]$releaseBranchPath")
在build PowerShell任务中,我传递
$path
变量,例如
$/MyProject/V1/Name
之后,我需要将文件夹转换为一个分支,因此我用C#编写了一个小工具(您需要TFS API库):
try
{
string collectionUrl = {myCollection};
string releaseBranchPath = Environment.GetEnvironmentVariable("releaseBranchPath");
var tp = TfsTeamProjectCollection(new Uri (collectionUrl));
var versionControl = tp.GetService<VersionControlServer>();
versionControl.CreateaBranchPbject(new BranchProperties(new ItemIdentifier(releaseBranchPath)));
}
catch (Execption e)
{
Console.WriteLine(e.Message);
}
我编译了它然后运行
.exe
在PowerShell任务之后使用命令行任务。