Reputation: 23
I have Continuous integration checked for my folder in TFS which triggers a build in 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? Help please
Upvotes: 2
Views: 494
Reputation: 29958
You can add a Powershell script task in your build definition to do this. 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.
Upvotes: 2
Reputation: 114461
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. 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.
Then you can use the tfpt getcs
option to get the changes of the changeset. You should be able to get the version from the builds Build.SourceVersion
variable. You can get tfpt
by installing the Team Foundation Server Power Tools 2015 and Team Explorer 2015 on the build server.
Upvotes: 2