Utility: Archive Files

VSTS | TFS 2018 | TFS 2017

Create an archive file from a source folder. A variety of standard archive formats are supported including: .zip, .jar, .war, .ear, .tar, .7z., and others.



YAML snippet

# Archive Files
# Archive files using compression formats such as .7z, .rar, .tar.gz, and .zip.
- task: ArchiveFiles@2
    #rootFolderOrFile: '$(Build.BinariesDirectory)' 
    #archiveType: 'zip' # Options: zip, 7z, tar, wim
    #tarCompression: 'gz' # Optional. Options: gz, bz2, xz, none
    #archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' 
    #replaceExistingArchive: true 


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 comprssed 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. See Variables.

Do I need an agent?

You need at least one agent to run your build or release. Get an agent.

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

See Agent pools and queues.

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

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