Skip to content
Latchkey

Compress-Archive: Create Zip Artifacts in CI

Compress-Archive creates a .zip from files or directories using only built-in PowerShell, so CI can package artifacts without installing 7-Zip.

For zipping build output into an uploadable artifact, Compress-Archive is the no-dependency option on any PowerShell 5.1+ or pwsh runner. Watch its handling of folder roots and overwrites.

What it does

Compress-Archive packs the items in -Path into a .zip at -DestinationPath. -Update adds/updates entries in an existing zip, and -Force overwrites an existing archive. Passing a folder includes its contents; ending the path with \* controls whether the top folder is included.

Common usage

PowerShell
# zip a folder's contents into an artifact
Compress-Archive -Path .\dist\* -DestinationPath .\artifact.zip -Force

# zip specific files
Compress-Archive -Path app.exe, README.md -DestinationPath release.zip -Force

# add more files to an existing archive
Compress-Archive -Path extra.dll -DestinationPath release.zip -Update

Options

ParameterWhat it does
-Path <items>Files/folders to include (accepts arrays, wildcards)
-DestinationPath <zip>Output .zip path
-ForceOverwrite an existing destination zip
-UpdateAdd or update entries in an existing zip
-CompressionLevel <lvl>Optimal, Fastest, or NoCompression

In CI

Use .\dist\* (not .\dist) when you want the zip to contain the folder's files at the root rather than nested under a dist directory. Add -Force so re-runs overwrite the previous archive instead of failing. For very large trees or >2GB entries, 7-Zip is more robust.

Common errors in CI

"The archive file ... already exists" means you omitted -Force on a re-run. "The path ... either does not exist or is not a valid file system path" often means a wildcard matched nothing, or a forward-slash path on a strict runner. "The file ... already exists in the archive" appears with -Update when adding a duplicate. Very long paths can trigger "The specified path, file name, or both are too long"; shorten the working directory.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →