简体   繁体   中英

Azure pipelines, Self-hosted agent, can I use a zip utility from scripts

I am working on Azure pipelines using a Windows Self-hosted Agent behind a firewall, after creating the artefact, I want to zip the current version that exists on the target folder and store the zip on a shared folder in case we need to rollback or compare.

I don't want to use a predefined task in the pipeline for that as the machine names and folders need to be hidden.

I created a PowerShell script that runs the 7-zip utility but I had to install it on a server and provide the full path to it while I believe some zip utility exists on the agent.

Are we allowed to reference a provided tools like that and is there a variable to it or should I simply install it on the agent server?

Any other recommended approach? Thanks.

There is no guarantee any tools that come with the current agent will:

  • remain the same version/compatible
  • keep shipping with the agent

The team building the agent tries to keep the agent as slim as acceptable. It also ships with the Azure DevOps Server DVD images where every bit counts. Tools have been removed in the past.

PowerShell

Depending on the features you need, PowerShell also has built-in archive support with compress-archive as of version 5. Which is for some time now, that wouldn't require you to install anything on the server.

On a sufficiently old PowerShell version you can tap into the .NET framework directly:

Zip:

PS C:\> Add-Type -A 'System.IO.Compression.FileSystem';
[IO.Compression.ZipFile]::CreateFromDirectory('C:\folder', 'C:\output.zip')

Unzip:

PS C:\> Add-Type -A 'System.IO.Compression.FileSystem';
[IO.Compression.ZipFile]::ExtractToDirectory('C:\input.zip', 'C:\output')

Windows

Windows also has built-in support for archiving with compress / expand .

You could also create a vhdx virtual drive, mount it and copy the files over. There are a number of options to turn on deduplication and a couple of other fancy features .

Very recent versions of windows also come with tar .

Alternate tools

Short term: you can rely on the tools to be there in the external tools folder of the agent.

Long term: A Tool Installer Task (allowing you different versions per pipeline) or a choco install or a winget install is going do be more reliable. You can also install the tool directly on the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM