ArchiveFiles@2 task. Failed with following error: zip warning: could not open for reading: .git/gc.pid

95 Views Asked by At

I’ve a failed job with the following errors when merging a pull request with DEV branch.

zip warning: could not open for reading: .git/gc.pid
zip warning: could not open for reading: .git/gc.log.lock

The build is successful when I push the repo to the azure devops.

This is the task for my pipeline:

- task: ArchiveFiles@2
  displayName: 'Archive Files'
  inputs:
    rootFolderOrFile: '$(buildRootDirectory)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true

Don't see any of those files .git/gc.pid and .git/gc.log.lock in my codebase.

1

There are 1 best solutions below

5
VonC On BEST ANSWER

Check if this is because of the Git garbage collection, by disabling temporarily gc, before the ArchiveFiles step:

- task: CmdLine@2
  displayName: 'Set gc.auto to 0'
  inputs:
    script: |
      git config --global gc.auto 0

... ArchiveFiles@2

- task: CmdLine@2
  displayName: 'Set gc.auto to default: restore gc'
  inputs:
    script: |
      git config --global --unset gc.auto

You might also want to clean out any gc file before the Archive step:

- task: PowerShell@2
  displayName: 'Cleanup gc files'
  inputs:
    targetType: 'inline'
    script: |
      $gcFiles = Get-ChildItem -Path "$(System.DefaultWorkingDirectory)" -Include .git\gc* -Recurse -Force
      if ($gcFiles) {
        Remove-Item -Path $gcFiles -Force -Recurse
      }