7-Zip compression levels in Azure DevOps Archive Files task

In an attempt to make my artifacts smaller, I recently chose to use 7-Zip compression, or archiveType: 7z, in an Archive Files task of an Azure DevOps YAML pipeline. 7-Zip provides 5 compression levels: 1 (fastest), 3 (fast), 5 (normal), 7 (maximum) and 9 (ultra), as well as option 0, which doesn’t compress anything.

I like YAML pipelines, because they live in my repo and I can use templates. However, the online editing experience is not particularly great. Sure, the online editor “assists” you when editing a simple file, but if you’re referencing templates, you’re out of luck (or at least I haven’t found a way to edit a template and use the “assistant”.)

Long story short, I’m editing a template (in a text editor) and I want to specify the compression level in my task. The official Archive Files task documentation page unfortunately doesn’t document the property that defines this. Luckily, a dummy pipeline and the “assistant” allowed me to quickly figure out that I wanted to set the sevenZipCompression property of the task. Of course, since the property wasn’t documented, neither were the values that it accepted. So with a little patience and using the task’s source code to confirm, I quickly came up with a table, which I decided to persist here for future reference:

LevelDescriptoinsevenZipCompression valueDefault
0No compression’none'
1Fastest compressing‘fastest’
3Fast compressing‘fast’
5Normal compressing’normal'yes
7Maximum compressing‘maximum’
9Ultra compressing‘ultra’

7-zip compression levels for the Azure Pipelines Archive files task

A complete example of the task would look something like this:

\- task: ArchiveFiles@2
  displayName: 'Compress Files'
    rootFolderOrFile: '$(Build.BinariesDirectory)'
    includeRootFolder: false
    archiveType: '7z'
    sevenZipCompression: 'maximum'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildNumber).zip'
    replaceExistingArchive: true

Illustration: Emballages compressés by Daniel Hennemand is licensed under CC BY-NC-ND 2.0