0

While Running a build in Azure DevOps (On Prem), one of the final steps is to add a folder to an archive before it can be put into a package for our deployment system.

The original zip is created within the same process block, we've had other similar errors within the same block either referring to the file being locked by another process, or that it does not have permission to access the file, all these actions are running on a remote server.

# Temp fix due to locking error
Copy-Item -Path ".\web\web_temp.zip" -Destination ".\web\web.zip"
Remove-Item -Path ".\web\web_temp.zip" -ErrorAction SilentlyContinue

# Add to web.zip
Compress-Archive -Path ".\_web\api" -Update -DestinationPath ".\web\web.zip"
Compress-Archive -Path ".\_web\dist" -Update -DestinationPath ".\web\web.zip"

Intermittently, we get an error when trying to update the archive:

New-Object : Exception calling ".ctor" with "2" argument(s): "The process cannot access the file 
'\web\web.zip' because it is being used by another 
process."
At 
C:\windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:729 
char:30
+ ... ileStream = New-Object -TypeName System.IO.FileStream -ArgumentList $ ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

I guess there's a possibility that two builds might be running at once, however they would create different folders within the remote server so should in theory have completely different work spaces.

Any help would be appreciated.

One of the attempts to fix can be seen above, copying as a web_temp.zip is an attempt to avoid another locking error that re occurs, which seems to be resolved with that fix, but then running the archive update seems to also lock the zip, intermittently though, only about 1 in 5 builds, the agents are azure vms added as agents to the on prem ado instance.

  • `Compress-Archive` doesnt open the filestream with `[FileShare] 'ReadWrite, Delete'` perhaps this answer helps: https://stackoverflow.com/a/72611161/15339544 – Santiago Squarzon May 18 '23 at 18:44

0 Answers0