1

I am trying to package only files that have been changed in the last 2 minutes using the built-in Team Foundation Server (TFS) build functionality from a git repository on the same TFS server.

I have written a PowerShell script to remove all old files that have a LastWriteTime older than 2 minutes:

# Get the current working directory
$currentDirectory = Get-Location

# Append the target directory to the current working directory
$targetDirectory = Join-Path $currentDirectory "CFM Reporting Project\SSRS\Reports"

# Get all files in the target directory and its subdirectories
Get-ChildItem -Recurse $targetDirectory | 
Where-Object {$_.LastWriteTime -lt (Get-Date).AddMinutes(-2)} | 
Remove-Item -Recurse -Force

# List all in target directory and its subdirectories
Get-ChildItem -Recurse $targetDirectory | Format-List -Property FullName,CreationTime,LastWriteTime,CheckinDate -Force  

I have ensured the build definition sets the Clean option to false.

TFS Build Definition

However, when building, no files are deleted because their LastWriteTimes are ALL the datetime at which the build started:

TFS build logs - folders

Here are further logs which show files since the above screenshot only shows folders: TFS build logs - files

I've used these sources for guidance and exploration of ideas:

Extra information

  • The deployment package consists of a repository of reports, not a Visual Studio solution file
  • Microsoft Visual Studio Team Foundation Server Version 16.131.28601.4
  • PowerShell Version 1.2.3

Can anyone give advice om how to package only the reports with changes in the last 2 minutes, especially since the LastWriteTime does is not working correctly.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • TFVC is a version control system, not a build system. Are you using TFVC for version control, or are you using Git? They are different things. – Daniel Mann Dec 26 '22 at 03:09
  • Hi @DanielMann - I’m using git as a source control system stored on Team Foundation Server, and using Team Foundation Server’s build and release functionality. – Jason Collier Dec 27 '22 at 06:14
  • Okay, then an important terminology note is that you are **not** using TFVC. I've edited your question accordingly. – Daniel Mann Dec 27 '22 at 22:57
  • Thanks @DanielMann. This is very specific to the Team Foundation Server build steps, so I've added that to the question otherwise my question will not get the desired outcomes. – Jason Collier Dec 28 '22 at 12:05

2 Answers2

1

The eventual solution was to use a PowerShell script to work out which files were edited in the last commit using git log as follows:

$modifiedFiles = git log -1 main --name-only --pretty=format:
0

Since you set the clean option to false, the pipeline will incrementally checkout changes of the repo.

From your screenshot about the date of the files, it shows change time at folder level not subfiles.

When sub-files in a folder change, the date of the folder will be updated together.

For example:

Subfiles:

enter image description here

Folder:

enter image description here

To package only the reports with changes in the last 2 minutes, you can check the date of the subfiles of the folder. Then you can package the related files.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • Hi Kevin, thanks for your comment! The sub-files have the exact same CreationTime and LastWriteTime timestamps as the parent folders - I've added another screenshot to the question to show this. – Jason Collier Dec 28 '22 at 12:18