简体   繁体   English

仅作为TFS构建的一部分从TFS中检入文件

[英]Get only checked in files from TFS as part of TFS build

I have Continuous integration checked for my folder in TFS which triggers a build in TFS2015 . 我在TFS中检查了我的文件夹的持续集成,触发了TFS2015中的构建。 Now as part of by Build Definition, I want to add a step which would identify and pull only those files which were checked in as part of the changeset which triggered the current build and copy them to a target location. 现在作为构建定义的一部分,我想添加一个步骤,该步骤将仅识别和拉取作为变更集的一部分签入的文件,这些文件触发当前构建并将它们复制到目标位置。

A powershell script may be? PowerShell脚本可能是? Help please 请帮助

This isn't possible in TFS 2015. TFS 2017 has introduced the ability to "don't sync sources", after which you can perform your own get operation. 这在TFS 2015中是不可能的.TFS 2017引入了“不同步源”的功能,之后您可以执行自己的获取操作。 You could try cloaking the whole repository on the repository tab and then creating a CI TFVC Include trigger definition on the trigger tab to recreate this behavior. 您可以尝试在存储库选项卡上隐藏整个存储库,然后在触发器选项卡上创建CI TFVC Include触发器定义以重新创建此行为。

Then you can use the tfpt getcs option to get the changes of the changeset. 然后,您可以使用tfpt getcs选项来获取更改集的更改。 You should be able to get the version from the builds Build.SourceVersion variable. 您应该能够从构建Build.SourceVersion变量获取版本。 You can get tfpt by installing the Team Foundation Server Power Tools 2015 and Team Explorer 2015 on the build server. 您可以通过在构建服务器上安装Team Foundation Server Power Tools 2015和Team Explorer 2015来获取tfpt

You can add a Powershell script task in your build definition to do this. 您可以在构建定义中添加Powershell脚本任务来执行此操作。 A simple script for your reference: 一个简单的脚本供您参考:

$changesetid = $Env:Build_SourceVersion
$TFSURI = $Env:System_TeamFoundationCollectionUri
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TFSURI)
$vcs = $tfs.GetService("Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer")
$cs = $vcs.GetChangeset($changesetid)
foreach ($change in $cs.Changes)
{
    $change.Item.DownloadFile('D:\a\test\' + $change.Item.ServerItem.Substring(1))
}

This code just get the changed items, if the changeset includes other changes like deletion, you may need to add code to check this. 此代码只获取更改的项目,如果更改集包含其他更改(如删除),您可能需要添加代码来检查此项。

And you also need to import the TFS Client Library to use this script, refer to this link for details: PowerShell and TFS: The Basics and Beyond . 您还需要导入TFS客户端库以使用此脚本,有关详细信息,请参阅此链接: PowerShell和TFS:基础知识及其他内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM