当将Azure DevOps CI / CD用于Linux Web应用程序时,如何压缩构建工件并将其作为zip文件发布,而不是复制到目录中

问题描述 投票:0回答:1

Per these instructions我正在为Linux Web App创建集成CI / CD的devops项目。

这是我最初的管道管道/构建工作

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '12.x'
  displayName: 'Install Node.js'

- script: |
    npm install -g @angular/cli
    npm install
    npm run build:ssr
  displayName: 'npm install and build'

- task: CopyFiles@2
  inputs:
    Contents: |
      dist/** 
      node_modules/**
      package.json
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
    CleanTargetFolder: true
    OverWrite: true

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

由于CopyFiles@2任务有65000个文件复制到要在以下PublishBuildArtifacts@1任务中发布的目录中。

因此,我想我可以在复制任务之后添加Artifact任务,这将产生一个.zip文件,并使部署效率更高,速度更快。

但是,情况并非如此,它所做的全部工作只是将文件夹压缩,解压缩文件夹并继续执行相同的单个文件处理,如下所示。在我写这篇文章的时候,已经花了大约14分钟,这已经走了多远。

Async Command Start: Upload Artifact
Uploading 65244 files
Total file: 65244 ---- Processed file: 69 (0%)
Total file: 65244 ---- Processed file: 200 (0%)
Total file: 65244 ---- Processed file: 333 (0%)
Total file: 65244 ---- Processed file: 460 (0%)
Total file: 65244 ---- Processed file: 603 (0%)
Total file: 65244 ---- Processed file: 746 (1%)
Total file: 65244 ---- Processed file: 884 (1%)
Total file: 65244 ---- Processed file: 1026 (1%)
Total file: 65244 ---- Processed file: 1142 (1%)
Total file: 65244 ---- Processed file: 1268 (1%)
Total file: 65244 ---- Processed file: 1365 (2%)
Total file: 65244 ---- Processed file: 1509 (2%)
Total file: 65244 ---- Processed file: 1672 (2%)
Total file: 65244 ---- Processed file: 1839 (2%)
Total file: 65244 ---- Processed file: 1993 (3%)
Total file: 65244 ---- Processed file: 2188 (3%)
Total file: 65244 ---- Processed file: 2362 (3%)
Total file: 65244 ---- Processed file: 2540 (3%)
Total file: 65244 ---- Processed file: 2701 (4%)
Total file: 65244 ---- Processed file: 2854 (4%)
Total file: 65244 ---- Processed file: 3051 (4%)
Total file: 65244 ---- Processed file: 3256 (4%)
Total file: 65244 ---- Processed file: 3459 (5%)
Total file: 65244 ---- Processed file: 3656 (5%)
Total file: 65244 ---- Processed file: 3836 (5%)
Total file: 65244 ---- Processed file: 4025 (6%)
Total file: 65244 ---- Processed file: 4196 (6%)
Total file: 65244 ---- Processed file: 4385 (6%)
Total file: 65244 ---- Processed file: 4545 (6%)
Total file: 65244 ---- Processed file: 4694 (7%)
Total file: 65244 ---- Processed file: 4864 (7%)
Total file: 65244 ---- Processed file: 5044 (7%)
Total file: 65244 ---- Processed file: 5253 (8%)
Total file: 65244 ---- Processed file: 5422 (8%)
Total file: 65244 ---- Processed file: 5620 (8%)

有没有一种方法可以满足我的需求?我是否应该复制然后压缩而不是仅压缩?这是因为它是Linux途径与Windows途径。

到目前为止,由于部署将花费一个小时,因此将无法利用。

这里是Deploy Azure App Service任务的任务

steps:
- task: AzureRmWebAppDeployment@4
  displayName: 'Deploy Azure App Service'
  inputs:
    azureSubscription: '$(Parameters.ConnectedServiceName)'
    appType: '$(Parameters.WebAppKind)'
    WebAppName: '$(Parameters.WebAppName)'
    packageForLinux: '$(System.DefaultWorkingDirectory)/**/**/*.zip'
    RuntimeStack: 'NODE|12-lts'
    StartupCommand: '$(Parameters.StartupCommand)'
azure azure-devops azure-web-app-service azure-webapps azure-ci-cd
1个回答
0
投票

是,您可以将特定的文件夹存档到zip,7z或tar存档中。然后,您可以仅将归档作为管道中的工件发布。这是将distnode_modulespackage.json内容归档到zip,然后将其作为工件发布的示例。

这里重要的一点是存档任务上的replaceExistingArchive: false,这会将每个文件夹/文件添加到存档中。一个例外是,如果您存档到压缩的TAR文件,则这些文件将始终被完全替换。 (Source

此外,Artifact任务只是发布文件,以便它们在管道外部可用,它不会将它们压缩为存档。

steps:
- task: ArchiveFiles@2
  displayName: 'Archive Dist Folder'
  inputs:
    rootFolderOrFile: 'dist'
    includeRootFolder: false
    archiveFile: '$(Build.ArtifactStagingDirectory)/archive.zip'
    replaceExistingArchive: false
- task: ArchiveFiles@2
  displayName: 'Archive node_modules Folder'
  inputs:
    rootFolderOrFile: 'node_modules'
    includeRootFolder: false
    archiveFile: '$(Build.ArtifactStagingDirectory)/archive.zip'
    replaceExistingArchive: false
- task: ArchiveFiles@2
  displayName: 'Archive package.json File'
  inputs:
    rootFolderOrFile: 'package.json'
    includeRootFolder: false
    archiveFile: '$(Build.ArtifactStagingDirectory)/archive.zip'
    replaceExistingArchive: false
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/archive.zip'
    ArtifactName: 'drop'
    publishLocation: 'Container'
© www.soinside.com 2019 - 2024. All rights reserved.