Azure DevOps仅存档从构建拖放中选择的文件?

时间:2019-11-14 14:44:10

标签: azure-devops azure-pipelines

在构建任务之后,是否有任何方法只能归档选定的文件? 我只找到“存档文件”任务,但它完全存档了整个文件夹。

1 个答案:

答案 0 :(得分:2)

  

Azure DevOps仅归档从构建删除中选择的文件吗?

恐怕没有这样的现成任务可以存档仅选中的文件而不是文件夹。

大多数现有任务(例如Archive filesZip and unzip directory build taskZip And Upload)都在服务于文件夹而不是多个文件。

就像Josh所说的那样,最直接的方法是将多个文件复制到目录中并将它们压缩在一起,以免使问题变得过于复杂。

但是,如果这个问题对您很重要,您可以尝试使用Powershell任务解决此问题:

Write-Output 'Archive selected files And folders'

$compress = @{
Path= "$(Build.SourcesDirectory)\dist\test.txt", "$(Build.SourcesDirectory)\test2.txt"
CompressionLevel = "Fastest"
DestinationPath = "$(Build.ArtifactStagingDirectory)\Draft.Zip"
}
Compress-Archive @compress

enter image description here

然后我可以存档多个文件。

如果要多个文件夹,可以使用以下命令:

Compress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft.zip

查看文档Compress-Archive,了解更多详细信息。

希望这会有所帮助。