azure-pipelines-tasks: After upgrade for version 4.0.0 of dependencie azure-pipelines-task, Archive2 does not work anymore

Yesterday after the commit for upgrade, it started to not work anymore, right after this https://github.com/microsoft/azure-pipelines-tasks/commit/e526642ad239018a1227109d12d93a182405a6fc :

Error logs

Found 0 files
/usr/bin/zip -r /home/vsts/work/1/a/6256.zip

zip error: Nothing to do! (/home/vsts/work/1/a/6256.zip)
##[error]Error: Archive creation failed for archive file: /home/vsts/work/1/a/6256.zip 
code: 12 
stdout: 
zip error: Nothing to do! (/home/vsts/work/1/a/6256.zip)
 
stderr:  
error: undefined;
##[error]Archive creation failed for archive file: /home/vsts/work/1/a/6256.zip 
code: 12 
stdout: 
zip error: Nothing to do! (/home/vsts/work/1/a/6256.zip)
 
stderr:  
error: undefined;

My yml

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 22

Most upvoted comments

I’ve same issue…

Logs:

stderr:  
error: Error: spawnSync /usr/bin/zip ENOBUFS
    at Object.spawnSync (node:internal/child_process:1111:20)
    at Object.spawnSync (node:child_process:814:24)
    at ToolRunner.execSync (/home/vsts/work/_tasks/ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0/2.211.0/node_modules/azure-pipelines-task-lib/toolrunner.js:879:23)
    at zipArchive (/home/vsts/work/_tasks/ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0/2.211.0/archivefiles.js:152:33)
    at createArchive (/home/vsts/work/_tasks/ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0/2.211.0/archivefiles.js:278:13)
    at doWork (/home/vsts/work/_tasks/ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0/2.211.0/archivefiles.js:338:9)
    at Object.<anonymous> (/home/vsts/work/_tasks/ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0/2.211.0/archivefiles.js:347:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32) {
  errno: -105,
  code: 'ENOBUFS',
  syscall: 'spawnSync /usr/bin/zip',
  path: '/usr/bin/zip',
  spawnargs: [Array]
};
##[error]Archive creation failed for archive file: /home/vsts/work/1/a/3470.zip

Task implementation:

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

I was able to work around this by specifying the pre-upgrade version of the task:

- task: ArchiveFiles@2.206.0

Upgrade appears to be in 178868e

This was the answer for us; works perfectly. Our task after changes:

- task: ArchiveFiles@2.206.0
    inputs: 
      rootFolderOrFile: .
      includeRootFolder: false
      archiveFile: ${{ parameters.outputZipPath }}

This was after a day working on custom zip/Compress-Archive solutions and running into the symlinking issues described above in our NextJS app.

EDIT: To add, thank you @mattford for this solution. I wasn’t aware until this that you could refer to tasks by minor version.

I was able to work around this by specifying the pre-upgrade version of the task:

- task: ArchiveFiles@2.206.0

Upgrade appears to be in https://github.com/microsoft/azure-pipelines-tasks/commit/178868ef50485c827548770e207c2d8cf251f62f

@liester I dont know of a way other than converting the entire pipeline to yaml 😕

Same issue here.

I tried @CaioDS solution but our code is a node app built from a lerna monorepo and some of the dependencies are symlinked. For whatever reason, the Azure Archive successfully bundles our nested/symlinked dependencies whereas the Compress-Archive script missed all of the symlinked ones and potentially some of the nested deps.

We wanted to implement @mattford solution, but our build pipelines are built with the classic editor instead of custom yaml files. Nevertheless inspired, we finally got things working again by selecting the 1.x task version from the classic editor dropdown for the Azure Archive task.

Classic Editor solution: classic-editor-version

So far we aren’t seeing any real consequences from downgrading to 1.x but YMMV.

Give this one a try as it zips symlinks also

  - script: zip -r --symlinks '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' .
    displayName: 'Archive files with symlinks'

@dcarnelossi @leni-msft I solved this problem by generating the zip file by the powershell core!

My old zip file generation task:

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

I replaced it with:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Compress-Archive -Path "$(System.DefaultWorkingDirectory)\*" -DestinationPath "$(Build.ArtifactStagingDirectory)\$(Build.BuildId).zip"
    pwsh: true

@ryan-bunkr We have several other steps to clear caches and install node and packages from scratch. I don’t know if it helps you but here is the build stage for our node + nextJS deploy pipeline.

- stage: Build
  displayName: Build stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)

    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '16.x'
      displayName: 'Install node.js'
    
    - script: npm update
      displayName: 'Update packages and install missing ones'

    - task: Cache@2
      displayName: 'Cache node_modules'
      inputs:
        key: node_modules | $(Agent.OS) | package.json
        path: '$(System.DefaultWorkingDirectory)/node_modules'

    - task: Cache@2
      displayName: 'Cache .next/cache'
      inputs:
        key: next | $(Agent.OS) | package.json
        path: '$(System.DefaultWorkingDirectory)/.next/cache'

    - script: npm run build
      displayName: 'Build for prod'

    - script: zip -r --symlinks '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' .
      displayName: 'Archive files with Bash zip while preserving symlinks'

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      artifact: drop

Another workaround is to use bash, and run a manual zip inline. This seems to avoid the issue around node

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: |
      cd $(Build.ArtifactStagingDirectory) && /usr/bin/zip -r $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip .