Windows Command Line Custom Script (Compare Two .txt Files)
I'm trying to run a build step that compares two files after the initial build.
expectedResults.txt is a constant that will not change
results.txt is a file that is overwritten during build and is filled with current Console.WriteLine() results.
I have tried a ton of variations using the commands and this includes absolute paths to the file names:
fc <Filename1> <Filename2>
and
comp
<Filename1>
<Filename2>
Option: /c
I typically get error code 2 “Cannot find file”
What syntax do I need or specific command in order to compare each file line by line.
The absolute file path is:
c:\Users\brjones\sctrayproj\brandens_learning_repo\day02\expectedResults.txt
and
c:\Users\brjones\sctrayproj\brandens_learning_repo\day02\results.txt
Please sign in to leave a comment.
Hi,
Have you been able to use fc or comp to achieve your comparison outside of TeamCity?
The TeamCity command line runner will execute the commands from the build agent working directory. If the files are not in the working directory, you will need to specify the full path to the files. You should be able to compare the two files line-by-line using the
fc
command in the same fashion as if you were doing it outside of TeamCity.Keep in mind, the build agent will need access to the location of the files. This would require the user that runs the build agent to have, at least, read access to the files. You may be seeing the “Cannot find file” error due to a permissions issue.
fc can never find the file within TeamCity
FC: cannot open C:\USERS\BRJONES\SCTRAYPROJ\BRANDENS_LEARNING_REPO\DAY02\RESULTS.TXT - No such file or folder
it will work within my CLI, but never in TeamCity
Comp also works in my CLI, but i believe this is build off of ReadLine() (C# equivalent) because it prompts me to insert an entry.
comp (Enter)
Name of first file to compare:
Name of second file to compare:
option:
I haven't found a way to insert the file path when prompted through the custom script.
What user is the build agent running as? Are you able to run your FC command with that user?
Does the file, C:\USERS\BRJONES\SCTRAYPROJ\BRANDENS_LEARNING_REPO\DAY02\RESULTS.TXT, exist on your build agent computer? Maybe try a simple command line runner with something like
dir “C:\USERS\BRJONES\SCTRAYPROJ\BRANDENS_LEARNING_REPO\DAY02\”
, just to make sure the build agent can access that location.