Error while applying the retention policy

We are facing a very fancy behavior with one of our Packages.
When Octopus deploy a new version it also try to remove the previous version using the policy associated with the retention rules.
The problem is that somehow 1 file can’t be deleted. We checked and the file is not read-only and is not in use but somehow the .NET DeleteHelper class bombs.
@@@
This is the error:
Beginning deployment…
Warning 16:52:10
An error occurred when applying the retention policy: Access to the path ‘ApplicationDatabaseLog.txt’ is denied.
Access to the path ‘ApplicationDatabaseLog.txt’ is denied.
System.UnauthorizedAccessException: Access to the path ‘ApplicationDatabaseLog.txt’ is denied.
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
at Octopus.Tentacle.Deployment.Journal.DeploymentJournal.ApplyRetentionPolicy(JournalEntry journalEntry, ILog log) in c:\TeamCity\buildAgent\work\1116bd9da9e239fd\source\Octopus.Tentacle\Deployment\Journal\DeploymentJournal.cs:line 105
at Octopus.Tentacle.Deployment.Journal.DeploymentJournal.AppendSuccessfulDeployment(JournalEntry journalEntry, ILog log) in c:\TeamCity\buildAgent\work\1116bd9da9e239fd\source\Octopus.Tentacle\Deployment\Journal\DeploymentJournal.cs:line 35
Info 16:52:10
Deployment complete.
@@@

Hi Raffaeu,

It looks as though either:

  • the file is being created by a different (more priviliged) user account than the one the Tentacle is running under, or
  • the process that writes the file is still running (this can sometimes happen even when the EXE file has been deleted)

Does either turn up any clues?

Regards,
Nick

Hi Nicholas, the script call an .exe application that is contained in the package and that creates this file inside the application folder at the end of the Deploy.ps1 execution, so the account is always the Octopus Tentacle service account and no process is locking the file, but it seems to be a permission problem.
I will investigate better the permissions or the read-only flags to see if that’s the issue.