本文介绍了将其他文件添加到Azure生成管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure DevOps管道,该管道从存储库中提取并构建Visual Studio Web项目.然后将其发布到App Service.

I have an Azure DevOps Pipeline which pulls from a repository and builds a Visual Studio web project. This is then published to an App Service.

我有几个敏感的配置文件,这些文件不包含在存储库(或VS项目)中,并存储为Azure DevOps系统中的安全文件".

I have several sensitive configuration files which are not included in the repository (or the VS project) and are stored as 'Secure Files' within the Azure DevOps system.

我需要将这些文件包含在要发布的软件包的"Config/Secure"文件夹中(在zip文件中).我可以下载它们,但是无论如何尝试,都无法将这些文件包含在部署zip文件中.它们仅出现在放置"文件系统中,因此我似乎无法将它们部署到Web App.

I need to include these files in the 'Config/Secure' folder for the package that gets published (within the zip file). I can download them, but no matter what I try, I cannot get these files to be included in the deployment zip file. They only appear in the 'drop' file system and thus I can't seem to deploy them to the Web App.

有人知道我该怎么做吗?在此先感谢您,并在下面提供管道YAML:

Does anyone have any ideas how I can do this? Thanks in advance and Pipeline YAML below:

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: DownloadSecureFile@1
  inputs:
    secureFile: 'AppSettings.secret.config'

- task: DownloadSecureFile@1
  inputs:
    secureFile: 'cache.secret.config'

- task: DownloadSecureFile@1
  inputs:
    secureFile: 'security.secret.config'

- task: DownloadSecureFile@1
  inputs:
    secureFile: 'Smtp.secret.config'

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Agent.TempDirectory)'
    Contents: |
      AppSettings.secret.config
      cache.secret.config
      security.secret.config
      Smtp.secret.config
    TargetFolder: '$(Build.ArtifactStagingDirectory)/config/secret'
    OverWrite: true
    flattenFolders: true

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)\\"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

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

推荐答案

我们无法将新文件直接添加到zip文件中.作为一种解决方法,我们可以提取文件夹 $(System.DefaultWorkingDirectory),将安全文件复制到 $(Build.ArtifactStagingDirectory)/PrescQIPPWebApp/config/secret 并压缩文件夹 $(Build.ArtifactStagingDirectory)/PrescQIPPWebApp ,然后发布工件.

We can't add new files directly to the zip file. As a workaround, we could Extract the folder $(System.DefaultWorkingDirectory), copy secure file to $(Build.ArtifactStagingDirectory)/PrescQIPPWebApp/config/secret and zip the folder $(Build.ArtifactStagingDirectory)/PrescQIPPWebApp, then publish the Artifact.

此外,由于解压缩后不会删除zip文件,并且存档后也不会删除 PrescQIPPWebApp 文件夹,因此我们需要添加 power shell 任务删除zip文件和 PrescQIPPWebApp 文件夹

In addition, since the zip file will not be deleted after extract, and the PrescQIPPWebApp folder also will not be deleted after archive, we need to add power shell task to delete the zip file and PrescQIPPWebApp folder

我已经更新了您的YAML构建定义,您可以尝试使用它,并在此处共享结果.

I have updated your YAML build definition, you could try it and kindly share the result here.

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)\\"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

#Extract PrescQIPPWebApp.zip file to $(Build.ArtifactStagingDirectory)/PrescQIPPWebApp folder
- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '$(Build.ArtifactStagingDirectory)/PrescQIPPWebApp.zip'
    destinationFolder: '$(Build.ArtifactStagingDirectory)/PrescQIPPWebApp'
    cleanDestinationFolder: false
    overwriteExistingFiles: false

#Delete PrescQIPPWebApp.zip file
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'Remove-Item ''$(Build.ArtifactStagingDirectory)/PrescQIPPWebApp.zip'''

- task: DownloadSecureFile@1
  inputs:
    secureFile: 'AppSettings.secret.config'

- task: DownloadSecureFile@1
  inputs:
    secureFile: 'cache.secret.config'

- task: DownloadSecureFile@1
  inputs:
    secureFile: 'security.secret.config'

- task: DownloadSecureFile@1
  inputs:
    secureFile: 'Smtp.secret.config'

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Agent.TempDirectory)'
    Contents: |
      AppSettings.secret.config
      cache.secret.config
      security.secret.config
      Smtp.secret.config
    TargetFolder: '$(Build.ArtifactStagingDirectory)/PrescQIPPWebApp/config/secret'
    OverWrite: true
    flattenFolders: true

#Archive file to PrescQIPPWebApp.zip
- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/PrescQIPPWebApp'
    includeRootFolder: true
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/PrescQIPPWebApp.zip'
    replaceExistingArchive: true

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

#Delete PrescQIPPWebApp folder
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'Remove-Item -path ''$(Build.ArtifactStagingDirectory)/PrescQIPPWebApp'' -Recurse -Force -EA SilentlyContinue -Verbose'

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

这篇关于将其他文件添加到Azure生成管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:34