TeamCity - problem reading text from same file a second time

Viewed 35

I'm seeing some peculiar behaviour in a TeamCity step that uses a cmd script.

In the example below, %USERPROFILE%\myfile.txt contains only the text "abc123" without quotes.

set /p myFileContent=<"%env.USERPROFILE%\myfile.txt"
echo "%%myFileContent%%"
set /p myFileContentTwo=<"%env.USERPROFILE%\myfile.txt"
echo "%%myFileContentTwo%%"

Output:

"abc123"
""

What is going on here? The file is read correctly first time, but not the second time. It works fine if I run the equivalent cmd script outside of TeamCity:

@echo off
set /p myFileContent=<"%USERPROFILE%\myfile.txt"
echo "%myFileContent%"
set /p myFileContentTwo=<"%USERPROFILE%\myfile.txt"
echo "%myFileContentTwo%"

Output:

"abc123"
"abc123"

I first observed this problem when reading the same file in two separate steps, with a wait of several seconds between reads, suggesting it's not a sharing violation. The file is intact and has the expected content after all steps have run.

I'm on TeamCity Enterprise 2021.2.1 (build 99602) on Windows 10.

0 Answers
Related