Archive Files task

Azure Pipelines | Azure DevOps Server 2019 | TFS 2018 | TFS 2017

Use this task in a build or release pipeline to create an archive file from a source folder. A range of standard archive formats are supported including .zip, .jar, .war, .ear, .tar, .7z, and more.



YAML snippet

# Archive files
# Compress files into .7z, .tar.gz, or .zip
- task: ArchiveFiles@2
    #rootFolderOrFile: '$(Build.BinariesDirectory)' 
    #includeRootFolder: true 
    #archiveType: 'zip' # Options: zip, 7z, tar, wim
    #tarCompression: 'gz' # Optional. Options: gz, bz2, xz, none
    #archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' 
    #replaceExistingArchive: true 
    #verbose: # Optional
    #quiet: # Optional


Argument Description
Root folder (or file) to archive

The folder (or file) you wish to archive. The default file path is relative from the root folder of the repo (same as if you had specified $(Build.SourcesDirectory)).

If the specified path is a folder, recursively, all nested files and folders will be included in the archive.

If the specified path is a file, only the single file will be included in the archive.

Prefix root folder name to archive paths If selected, the root folder name will be prefixed to file paths within the archive. Otherwise, all file paths will start one level lower.

For example, suppose the selected root folder is: /home/user/output/classes/, and contains: com/acme/Main.class.

  • If selected, the resulting archive would contain: classes/com/acme/Main.class.
  • Otherwise, the resulting archive would contain: com/acme/Main.class..
Archive type Specify the compression scheme used. To create foo.jar, for example, choose zip for the compression, and specify foo.jar as the archive file to create. For all tar files (including compressed ones), choose tar.

  • zip - default, zip format, choose this for all zip compatible types, (.zip, .jar, .war, .ear)
  • 7z - 7-Zip format, (.7z)
  • tar - tar format, choose this for compressed tars, (.tar.gz, .tar.bz2, .tar.xz)
  • wim - wim format, (.wim)
Tar compression Only applicable if the tar archive type is selected.

Optionally choose a compression scheme, or choose None to create an uncompressed tar file.

  • gz - default, gzip compression (.tar.gz, .tar.tgz, .taz)
  • bz2 - bzip2 compression (.tar.bz2, .tz2, .tbz2)
  • xz - xz compression (.tar.xz, .txz)
  • None - no compression, choose this to create a uncompressed tar file (.tar)
Archive file to create Specify the name of the archive file to create. The file extension should match the selected archive type. For example to create foo.tgz, select the tar archive type, gz for tar compression.
Replace existing archive If an existing archive exists, specify whether to overwrite it. Otherwise, files will be added to it as long as it is not a compressed tar.

If adding to an existing archive, these types are supported:

  • zip
  • 7z
  • tar - uncompressed only
  • wim
Control options

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

Q: I'm having problems. How can I troubleshoot them?

A: Try this:

  1. On the variables tab, add system.debug and set it to true. Select to allow at queue time.

  2. In the explorer tab, view your completed build and click the build step to view its output.

The control options arguments described above can also be useful when you're trying to isolate a problem.

Q: How do variables work? What variables are available for me to use in the arguments?

A: $(Build.SourcesDirectory) and $(Agent.BuildDirectory) are just a few of the variables you can use. Variables are available in expressions as well as scripts; see variables to learn more about how to use them. There are some predefined build and release variables you can also rely on.

Do I need an agent?

You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.

I'm having problems. How can I troubleshoot them?

See Troubleshoot Build and Release.

I can't select a default agent pool and I can't queue my build or release. How do I fix this?

See Agent pools.

I use TFS on-premises and I don't see some of these features. Why not?

Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.