I am running an onsite TFS 2017 Build Server.
As part of my process, I delete all existing files in a target folder (using the Delete Files Utility).
This works almost every time, however, some sort of permission gets messed up on a file and this process is unable to delete it. Manually deleting the file from Explorer fixes things, but I would like to be able to delete files automatically using my build process.
I have checked and the TFS Service Account has has full rights to the file.
Here is the error
##[section]Starting: Clean Files
==============================================================================
Task : Delete Files
Description : Delete files or folders. (The minimatch patterns will only match file paths, not folder paths)
Version : 1.1.3
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=722333)
==============================================================================
##[error]Error: Failed rmRF: EPERM: operation not permitted, unlink 'C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files\181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png'
##[error]Error: Failed rmRF: EPERM: operation not permitted, unlink 'C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files\181007DF9C61D440A64FE881E76E727DFFD702.jpg'
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files/181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files/181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files/181007DF9C61D440A64FE881E76E727DFFD702.jpg
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files/181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files/181007DF9C61D440A64FE881E76E727DFFD702.jpg
rm: could not remove directory (code ENOTEMPTY): C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files
##[error]Error: Failed rmRF: rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files/181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files/181007DF9C61D440A64FE881E76E727DFFD702.jpg
rm: could not remove directory (code ENOTEMPTY): C:\Web\Nodes\hercules\Content\member-int.buzz\Content\Files
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files/181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files/181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files/181007DF9C61D440A64FE881E76E727DFFD702.jpg
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files/181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files/181007DF9C61D440A64FE881E76E727DFFD702.jpg
rm: could not remove directory (code ENOTEMPTY): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files/181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files/181007DF9C61D440A64FE881E76E727DFFD702.jpg
rm: could not remove directory (code ENOTEMPTY): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files
rm: could not remove directory (code ENOTEMPTY): C:\Web\Nodes\hercules\Content\member-int.buzz\Content
##[error]Error: Failed rmRF: rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files/181007DF9C61D440A64FE881E76E727DFFD702-THUMB.png
rm: could not remove file (code EPERM): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files/181007DF9C61D440A64FE881E76E727DFFD702.jpg
rm: could not remove directory (code ENOTEMPTY): C:\Web\Nodes\hercules\Content\member-int.buzz\Content/Files
rm: could not remove directory (code ENOTEMPTY): C:\Web\Nodes\hercules\Content\member-int.buzz\Content
##[error]Couldn't delete one or more files
##[section]Finishing: Clean Files
It's not always the same file that gets messed up.