4

Lately I have been facing this error for one of my release definition and I am not able to figure it out why is this happening.

I tried manually deleting the folders inside the r1 directory but it fails to delete the 'a' folder i.e. artifact directory and says the folder or file in it is open in another program. But its shocking that the 'a' folder is empty and don't even have a hidden files and folders in it.

As a work around, to make the release successfully get deployed I have to restart my server each time whenever I want a new release to be deployed. Which is really very annoying.

Below is the complete error that I get on the Release definition summary.

Errors (2)

 Downloading artifacts failed: Microsoft.VisualStudio.Services.Agent.Worker.Release.Artifacts.ArtifactDirectoryCreationFailedException: Failed to create Release artifact directory 'C:\Agents\DA_CID22\r1\a'. ---> System.IO.IOException: The process cannot access the file '\?\C:\Agents\DA_CID22\r1\a' because it is being used by another process. at System.IO.Win32FileSystem.RemoveDirectoryHelper(String fullPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound) at System.IO.Win32FileSystem.RemoveDirectory(String fullPath, Boolean recursive) at Microsoft.VisualStudio.Services.Agent.Util.IOUtil.DeleteDirectory(String path, Boolean contentsOnly, Boolean continueOnContentDeleteError, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.Agent.Worker.Release.ReleaseFileSystemManager.EnsureEmptyDirectory(String directoryPath, CancellationToken cancellationToken) --- End of inner exception stack trace --- at Microsoft.VisualStudio.Services.Agent.Worker.Release.ReleaseFileSystemManager.EnsureEmptyDirectory(String directoryPath, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.Agent.Worker.Release.RetryExecutor.Execute(Action action) at Microsoft.VisualStudio.Services.Agent.Worker.Release.ReleaseJobExtension.CreateArtifactsFolder(IExecutionContext executionContext, String artifactsWorkingFolder) at Microsoft.VisualStudio.Services.Agent.Worker.Release.ReleaseJobExtension.d__34.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.Services.Agent.Worker.Release.ReleaseJobExtension.d__31.MoveNext()

 Failed to create Release artifact directory 'C:\Agents\DA_CID22\r1\a'.

Any help or advice would be really helpful.

SRP
  • 999
  • 4
  • 21
  • 39
  • Can you give us an overview of the steps in your release definition? Would expect one of those processes to hold on the directory itself? Have you tested it with all steps disabled? – Rob Bos Dec 02 '18 at 15:29
  • @Rob Bos, Yes , I have 20 steps in that Release definition and I have disabled 19 steps in it and i am testing one PowerShell step in it. The steps\task in this Release definition are like start\stop services, Start\Stop IIS, Deploy some code and Executing the PowerShell Script. – SRP Dec 03 '18 at 07:14
  • @Rob Bos, I am facing this issue for all the Release definition when i try to redploy the code. This is happening even for Release definition that has one task in it. Which is the process that using it i am not able to figure it out. – SRP Dec 05 '18 at 14:09
  • Just to doublecheck: you are using a private agent for this? Checked antivirus and stuff like that? Maybe install the agent as a new one next to this and see if that has the same issue? – Rob Bos Dec 08 '18 at 08:27
  • @Rob Bos, As a work around I Tried that as well. I installed new agent but still the same issue. – SRP Dec 10 '18 at 14:37

1 Answers1

3

This happens from time to time...I spent days trying to figure out with no easy solution (all the ones you have tried, I tried myself) but for restarting the private agent. My conclusion is that somehow the agent process got hung with the artifact Windows folder. You can see that with programs like https://lockhunter.com/. There's not an easy solution here...Sometimes you must kill the culprit process which not ended correctly freeing that file, or if you are lucky releasing the file handle to that file with a tool like said before...

Zodraz
  • 131
  • 1
  • 7
  • 1
    This happens to us too. I just restart the server. It'd be nice to know why/what is locking the directory. – Alex Kwitny Feb 11 '19 at 16:59
  • Use PowerShell `Get-SmbOpenFile` then `Close-SmbOpenFile` as needed. To get to the build server, you can use 'Enter-PsSession` and run the above commands. – AMissico Jun 11 '21 at 19:12