如何通过管道从 Library Secure 文件传播文件?
How to propagate files from Library Secure files through pipeline?
我们有一个 CI/CD 当前生成工件的管道,发布管道将工件传播到整个非生产阶段,并最终传播到生产阶段。
开发人员向 Azure 管道“库”添加了一些安全文件,并希望在部署过程中自动包含这些文件。目前,他必须在每次发布管道运行时继续上传它们,因为它会用新的工件构建覆盖现有工件。
此外,其中一个安全文件(Test-DocuSign-private.key)应该重命名为“private.key”(是否before/after部署,哪个更合理)。
哪些任务可以实现这一点(即从库中提取安全文件并将它们传播为工件部署的一部分)
这是我的 App Service Deploy YAML 和下载安全文件和 powershell 任务,我作为原型添加到我想要完成的任务中(注意复制下载安全文件和复制任务)。
这是将安全文件添加(复制)到 Azure 应用服务部署之前生成(称为发布)的 CI 构建工件的正确方法吗?
steps:
- task: qetza.replacetokens.replacetokens-task.replacetokens@4
displayName: 'Replace tokens in **/Web.config'
inputs:
rootDirectory: '$(System.DefaultWorkingDirectory)/Build Artifact/Release'
targetFiles: '**/Web.config'
tokenPattern: custom
tokenPrefix: '<mailSettings>'
tokenSuffix: '</mailSettings>'
steps:
- task: DownloadSecureFile@1
displayName: GoogleServiceAccountKey
inputs:
secureFile: GoogleServiceAccountKey.json
retryCount: 2
steps:
- task: DownloadSecureFile@1
displayName: DocuSignPrivateKey
inputs:
secureFile: 'Test-DocuSign-private.key'
retryCount: 2
steps:
- powershell: |
#Copy GoogleServiceAccountKey.json file
Copy-Item -Path "$(GoogleServiceAccountKey.secureFilePath)" -Destination "$(System.DefaultWorkingDirectory)/Build Artifact/Release/GoogleServiceAccountKey.json"
#Copy and rename *Env*-DocuSign-private.key file to private.key
Copy-Item -Path "$(DocuSignPrivateKey.secureFilePath)" -Destination "$(System.DefaultWorkingDirectory)/Build Artifact/Release/private.key"
displayName: 'Copy Secure Files to Release Artifact'
steps:
- task: AzureRmWebAppDeployment@4
displayName: 'Azure App Service Deploy: ee-dev'
inputs:
azureSubscription: 'Azure Dev Service Connection'
WebAppName: 'ee-dev'
packageForLinux: '$(System.DefaultWorkingDirectory)/Build Artifact/Release'
enableCustomDeployment: true
RemoveAdditionalFilesFlag: true
AdditionalArguments: '-skip:objectName=filePath,absolutePath="Web.Dev.config|Web.Test.config|Web.Prod.config|Web.Sandbox.config|Web.Beta.config|\*.zip" -retryAttempts:6 -retryInterval:10000'
enableXmlTransform: true
只要您 运行 使用 windows 代理,这应该可以工作。但是,您应该注意 windows 上的路径分隔符“/”。
我宁愿在任何代理上使用可以 运行 的更通用的任务。在此处添加 link 以供参考:https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/powershell?view=azure-devops
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
#Copy GoogleServiceAccountKey.json file
Copy-Item -Path "$(GoogleServiceAccountKey.secureFilePath)" -Destination "$(System.DefaultWorkingDirectory)/Build Artifact/Release/GoogleServiceAccountKey.json"
#Copy and rename *Env*-DocuSign-private.key file to private.key
Copy-Item -Path "$(DocuSignPrivateKey.secureFilePath)" -Destination "$(System.DefaultWorkingDirectory)/Build Artifact/Release/private.key"
displayName: 'Copy Secure Files to Release Artifact'
我们有一个 CI/CD 当前生成工件的管道,发布管道将工件传播到整个非生产阶段,并最终传播到生产阶段。
开发人员向 Azure 管道“库”添加了一些安全文件,并希望在部署过程中自动包含这些文件。目前,他必须在每次发布管道运行时继续上传它们,因为它会用新的工件构建覆盖现有工件。
此外,其中一个安全文件(Test-DocuSign-private.key)应该重命名为“private.key”(是否before/after部署,哪个更合理)。
哪些任务可以实现这一点(即从库中提取安全文件并将它们传播为工件部署的一部分)
这是我的 App Service Deploy YAML 和下载安全文件和 powershell 任务,我作为原型添加到我想要完成的任务中(注意复制下载安全文件和复制任务)。 这是将安全文件添加(复制)到 Azure 应用服务部署之前生成(称为发布)的 CI 构建工件的正确方法吗?
steps:
- task: qetza.replacetokens.replacetokens-task.replacetokens@4
displayName: 'Replace tokens in **/Web.config'
inputs:
rootDirectory: '$(System.DefaultWorkingDirectory)/Build Artifact/Release'
targetFiles: '**/Web.config'
tokenPattern: custom
tokenPrefix: '<mailSettings>'
tokenSuffix: '</mailSettings>'
steps:
- task: DownloadSecureFile@1
displayName: GoogleServiceAccountKey
inputs:
secureFile: GoogleServiceAccountKey.json
retryCount: 2
steps:
- task: DownloadSecureFile@1
displayName: DocuSignPrivateKey
inputs:
secureFile: 'Test-DocuSign-private.key'
retryCount: 2
steps:
- powershell: |
#Copy GoogleServiceAccountKey.json file
Copy-Item -Path "$(GoogleServiceAccountKey.secureFilePath)" -Destination "$(System.DefaultWorkingDirectory)/Build Artifact/Release/GoogleServiceAccountKey.json"
#Copy and rename *Env*-DocuSign-private.key file to private.key
Copy-Item -Path "$(DocuSignPrivateKey.secureFilePath)" -Destination "$(System.DefaultWorkingDirectory)/Build Artifact/Release/private.key"
displayName: 'Copy Secure Files to Release Artifact'
steps:
- task: AzureRmWebAppDeployment@4
displayName: 'Azure App Service Deploy: ee-dev'
inputs:
azureSubscription: 'Azure Dev Service Connection'
WebAppName: 'ee-dev'
packageForLinux: '$(System.DefaultWorkingDirectory)/Build Artifact/Release'
enableCustomDeployment: true
RemoveAdditionalFilesFlag: true
AdditionalArguments: '-skip:objectName=filePath,absolutePath="Web.Dev.config|Web.Test.config|Web.Prod.config|Web.Sandbox.config|Web.Beta.config|\*.zip" -retryAttempts:6 -retryInterval:10000'
enableXmlTransform: true
只要您 运行 使用 windows 代理,这应该可以工作。但是,您应该注意 windows 上的路径分隔符“/”。 我宁愿在任何代理上使用可以 运行 的更通用的任务。在此处添加 link 以供参考:https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/powershell?view=azure-devops
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
#Copy GoogleServiceAccountKey.json file
Copy-Item -Path "$(GoogleServiceAccountKey.secureFilePath)" -Destination "$(System.DefaultWorkingDirectory)/Build Artifact/Release/GoogleServiceAccountKey.json"
#Copy and rename *Env*-DocuSign-private.key file to private.key
Copy-Item -Path "$(DocuSignPrivateKey.secureFilePath)" -Destination "$(System.DefaultWorkingDirectory)/Build Artifact/Release/private.key"
displayName: 'Copy Secure Files to Release Artifact'