3

I'm trying to zip a Rust debug build folder using the ArchiveFiles task in my Azure pipeline. This fails with the error message:

##[error]Error: Archive creation failed for archive file: D:\a\1\a\MyProject-win-33.zip

This is the yaml for ArchiveFiles:

  - task: ArchiveFiles@2
    inputs:
      rootFolderOrFile: '$(Build.BinariesDirectory)/target/debug'
      includeRootFolder: true
      archiveType: 'zip'
      archiveFile: '$(Build.ArtifactStagingDirectory)/MyProject-$(build)-$(Build.BuildId).zip'
      replaceExistingArchive: true
      verbose: true

And here are the full output of a verbose task log with System.Debug set to true:

2021-01-09T23:55:48.6172670Z ##[debug]Evaluating condition for step: 'ArchiveFiles'
2021-01-09T23:55:48.6174643Z ##[debug]Evaluating: SucceededNode()
2021-01-09T23:55:48.6175445Z ##[debug]Evaluating SucceededNode:
2021-01-09T23:55:48.6176652Z ##[debug]=> True
2021-01-09T23:55:48.6177228Z ##[debug]Result: True
2021-01-09T23:55:48.6178206Z ##[section]Starting: ArchiveFiles
2021-01-09T23:55:48.6303073Z ==============================================================================
2021-01-09T23:55:48.6303384Z Task         : Archive files
2021-01-09T23:55:48.6303616Z Description  : Compress files into .7z, .tar.gz, or .zip
2021-01-09T23:55:48.6304004Z Version      : 2.179.0
2021-01-09T23:55:48.6304379Z Author       : Microsoft Corporation
2021-01-09T23:55:48.6304683Z Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/archive-files
2021-01-09T23:55:48.6305000Z ==============================================================================
2021-01-09T23:55:48.6488004Z ##[debug]Using node path: C:\agents\2.179.0\externals\node10\bin\node.exe
2021-01-09T23:55:49.0940866Z ##[debug]agent.TempDirectory=D:\a\_temp
2021-01-09T23:55:49.0964617Z ##[debug]loading inputs and endpoints
2021-01-09T23:55:49.0983185Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2021-01-09T23:55:49.1093409Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2021-01-09T23:55:49.1096519Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2021-01-09T23:55:49.1099079Z ##[debug]loading INPUT_ARCHIVEFILE
2021-01-09T23:55:49.1101178Z ##[debug]loading INPUT_ARCHIVETYPE
2021-01-09T23:55:49.1103385Z ##[debug]loading INPUT_INCLUDEROOTFOLDER
2021-01-09T23:55:49.1105630Z ##[debug]loading INPUT_QUIET
2021-01-09T23:55:49.1108117Z ##[debug]loading INPUT_REPLACEEXISTINGARCHIVE
2021-01-09T23:55:49.1110533Z ##[debug]loading INPUT_ROOTFOLDERORFILE
2021-01-09T23:55:49.1112588Z ##[debug]loading INPUT_SEVENZIPCOMPRESSION
2021-01-09T23:55:49.1114939Z ##[debug]loading INPUT_TARCOMPRESSION
2021-01-09T23:55:49.1116869Z ##[debug]loading INPUT_VERBOSE
2021-01-09T23:55:49.1123273Z ##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
2021-01-09T23:55:49.1130786Z ##[debug]loaded 13
2021-01-09T23:55:49.1135334Z ##[debug]Agent.ProxyUrl=undefined
2021-01-09T23:55:49.1136491Z ##[debug]Agent.CAInfo=undefined
2021-01-09T23:55:49.1137088Z ##[debug]Agent.ClientCert=undefined
2021-01-09T23:55:49.1137595Z ##[debug]Agent.SkipCertValidation=undefined
2021-01-09T23:55:49.1143104Z ##[debug]System.DefaultWorkingDirectory=D:\a\1\s
2021-01-09T23:55:49.1153711Z ##[debug]rootFolderOrFile=D:\a\1\b\target\release
2021-01-09T23:55:49.1154416Z ##[debug]makeAbsolute:D:\a\1\b\target\release
2021-01-09T23:55:49.1157283Z ##[debug]includeRootFolder=true
2021-01-09T23:55:49.1158804Z ##[debug]archiveType=zip
2021-01-09T23:55:49.1160944Z ##[debug]archiveFile=D:\a\1\a\MyProject-win-33.zip
2021-01-09T23:55:49.1162448Z ##[debug]replaceExistingArchive=true
2021-01-09T23:55:49.1163806Z ##[debug]verbose=true
2021-01-09T23:55:49.1165133Z ##[debug]quiet=false
2021-01-09T23:55:49.1165602Z ##[debug]repoRoot: D:\a\1\s
2021-01-09T23:55:49.1172347Z ##[debug]win: Win
2021-01-09T23:55:49.1179483Z ##[debug]check path : D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\task.json
2021-01-09T23:55:49.1258869Z ##[debug]adding resource file: D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\task.json
2021-01-09T23:55:49.1260426Z ##[debug]system.culture=en-US
2021-01-09T23:55:49.1293980Z Found 1 files
2021-01-09T23:55:49.1296045Z Archiving file: release
2021-01-09T23:55:49.1296630Z ##[debug]Listing all 1 files to archive:
2021-01-09T23:55:49.1297020Z ##[debug]release
2021-01-09T23:55:49.1300320Z ##[debug]Checking for archive destination folder:D:\a\1\a
2021-01-09T23:55:49.1305158Z ##[debug]Creating archive with 7-zip: D:\a\1\a\MyProject-win-33.zip
2021-01-09T23:55:49.1310775Z ##[debug]which 'D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe'
2021-01-09T23:55:49.1319604Z ##[debug]found: 'D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe'
2021-01-09T23:55:49.1321461Z ##[debug]D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe arg: a
2021-01-09T23:55:49.1322527Z ##[debug]D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe arg: -tzip
2021-01-09T23:55:49.1323687Z ##[debug]D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe arg: -bb3
2021-01-09T23:55:49.1324510Z ##[debug]sevenZipCompression=5
2021-01-09T23:55:49.1325292Z ##[debug]D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe arg: -mx=5
2021-01-09T23:55:49.1327334Z ##[debug]D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe arg: D:\a\1\a\MyProject-win-33.zip
2021-01-09T23:55:49.1328387Z ##[debug]Agent.TempDirectory=D:\a\_temp
2021-01-09T23:55:49.1329612Z ##[debug]D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe arg: @D:\a\_temp\v0bycktans
2021-01-09T23:55:49.1330806Z ##[debug]cwd (include root folder)= D:\a\1\b\target
2021-01-09T23:55:49.1332246Z ##[debug]exec tool: D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe
2021-01-09T23:55:49.1332719Z ##[debug]arguments:
2021-01-09T23:55:49.1333379Z ##[debug]   a
2021-01-09T23:55:49.1333967Z ##[debug]   -tzip
2021-01-09T23:55:49.1334528Z ##[debug]   -bb3
2021-01-09T23:55:49.1335111Z ##[debug]   -mx=5
2021-01-09T23:55:49.1335728Z ##[debug]   D:\a\1\a\MyProject-win-33.zip
2021-01-09T23:55:49.1336381Z ##[debug]   @D:\a\_temp\v0bycktans
2021-01-09T23:55:49.1342541Z [command]D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe a -tzip -bb3 -mx=5 D:\a\1\a\MyProject-win-33.zip @D:\a\_temp\v0bycktans
2021-01-09T23:55:49.1396505Z ##[debug]execResult: {"code":null,"error":{"errno":"ENOENT","code":"ENOENT","syscall":"spawnSync D:\\a\\_tasks\\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\\2.179.0\\7zip\\7z.exe","path":"D:\\a\\_tasks\\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\\2.179.0\\7zip\\7z.exe","spawnargs":["a","-tzip","-bb3","-mx=5","D:\\a\\1\\a\\MyProject-win-33.zip","@D:\\a\\_temp\\v0bycktans"]},"stdout":"","stderr":""}
2021-01-09T23:55:49.1399073Z ##[debug]Archive creation failed for archive file: D:\a\1\a\MyProject-win-33.zip 
code: 0 
stdout:  
stderr:  
error: Error: spawnSync D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe ENOENT;
2021-01-09T23:55:49.1434709Z ##[error]Error: Archive creation failed for archive file: D:\a\1\a\MyProject-win-33.zip 
code: 0 
stdout:  
stderr:  
error: Error: spawnSync D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe ENOENT;
2021-01-09T23:55:49.1445687Z ##[debug]Processed: ##vso[task.issue type=error;]Error: Archive creation failed for archive file: D:\a\1\a\MyProject-win-33.zip %0Acode: 0 %0Astdout:  %0Astderr:  %0Aerror: Error: spawnSync D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe ENOENT;
2021-01-09T23:55:49.1447274Z ##[debug]task result: Failed
2021-01-09T23:55:49.1448528Z ##[error]Archive creation failed for archive file: D:\a\1\a\MyProject-win-33.zip 
code: 0 
stdout:  
stderr:  
error: Error: spawnSync D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe ENOENT;
2021-01-09T23:55:49.1450183Z ##[debug]Processed: ##vso[task.issue type=error;]Archive creation failed for archive file: D:\a\1\a\MyProject-win-33.zip %0Acode: 0 %0Astdout:  %0Astderr:  %0Aerror: Error: spawnSync D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe ENOENT;
2021-01-09T23:55:49.1458570Z ##[debug]Processed: ##vso[task.complete result=Failed;]Archive creation failed for archive file: D:\a\1\a\MyProject-win-33.zip %0Acode: 0 %0Astdout:  %0Astderr:  %0Aerror: Error: spawnSync D:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.179.0\7zip\7z.exe ENOENT;
2021-01-09T23:55:49.1559430Z ##[section]Finishing: ArchiveFiles

I don't understand the error message, and I have made sure the folder exists.

mottosson
  • 3,283
  • 4
  • 35
  • 73
  • I faced this issue before and it's because there are x86 agents and all the tasks that include 7zip are created to work only for x64. This is because OS architecture is not taken into account when including resources. – Osamazx Jan 10 '21 at 00:56
  • Oh, strange! So you know of any workaround or alternative solution? – mottosson Jan 10 '21 at 01:14

2 Answers2

2

Azure pipelines ArchiveFiles Archive creation failed

There is an issue Extract Files task failed on x86 agent on github about it:

This is a real problems because there are x86 agents and all the tasks that include 7zip are created to work only for x64. This is because OS architecture is not taken into account when including resources. Problems until now with the following tasks ExtractFiles/ArchiveFiles.

To resolve this issue, you could try to use powershell scripts to archive files:

- task: PowerShell@2
  displayName: 'Inline Powershell'
  inputs:
    TargetType: inline
    Script: |
     Compress-Archive -Path "$(Build.BinariesDirectory)\target\debug" -DestinationPath "$(Build.ArtifactStagingDirectory)\MyProject-$(build)-$(Build.BuildId).zip"
    pwsh: true

Check the document Compress-Archive for some more details.

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    Can I run PowerShell script on other OS than Windows? I'm currently building my project on Mac, Windows and Linux and need to be able to compress files on all of them. – mottosson Jan 11 '21 at 10:14
  • @mottosson, The answer is yes, you could provide the Argument `pwsh: true`. Please check the updated answer and the document for some more details: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/powershell?view=azure-devops – Leo Liu Jan 12 '21 at 02:19
0

I had the same error using the Archive Files task on a custom Linux build agent which failed with the error "Error: spawnSync /usr/bin/zip ENOENT"

It worked when I untick "Prepend root folder name to archive paths" in the release UI which presumably maps to your setting includeRootFolder: true, so changing this to false may also fix it if this is the same issue.

Andy
  • 160
  • 1
  • 9