[英]How to deploy to different environment in Azure Devops using YAML file
你能帮我在下面吗?
I am building Azure Function app V3 and using Azure Devops YAML pipeline to build and deploy Azure function app and ARM infra to Dev environment. 现在我想将其部署到 UAT。 我不确定如何使用 YAML 拥有不同的环境。 请找到我正在使用的azure-pipeline.yml
文件
name: $(Build.DefinitionName)-$(Date:yyyyMMdd)$(Rev:.r)
trigger:
- dev
resources:
repositories:
- repository: pipeline
name: Pipeline
type: git
pool:
vmImage: 'windows-latest'
variables:
- name: Folder.BaseRepo # Location in repo where the templates are stored
value: $(Build.SourcesDirectory)/Finance
- name: Folder.Templates # Location in repo where the templates are stored
value: infrastructure
stages:
- stage: Build
displayName: 'Build'
jobs:
- job: PublishTemplatesAndScripts
displayName: 'Publish Templates and Scripts'
steps:
- template: 'publish-templates.yml@pipeline'
parameters:
templateFolder: '$(Folder.Templates)'
artifactName: 'templates'
pipelineRepository: pipeline
pipelineRepositoryPath: pipeline
- task: DotNetCoreCLI@2
displayName: 'Restore dependencies'
inputs:
command: 'restore'
projects: '$(Folder.BaseRepo)/Finance.sln'
feedsToUse: 'select'
vstsFeed: 'ac1301c4-6618-4824-a09e-0042d9871fb5/58ed1ece-4d06-46f7-b947-XXXX36281c4'
enabled: true
- task: DotNetCoreCLI@2
displayName: 'Build function app'
inputs:
projects: '$(Folder.BaseRepo)/Finance.sln'
command: 'build'
arguments: '--configuration Release'
enabled: true
- task: DotNetCoreCLI@2
displayName: 'Test function app'
inputs:
projects: '$(Folder.BaseRepo)/Finance.sln'
command: 'test'
arguments: '--configuration Release'
enabled: false
- task: DotNetCoreCLI@2
displayName: 'Publish function app'
inputs:
command: 'publish'
publishWebProjects: false
projects: '$(Folder.BaseRepo)/src/Finance/Finance.csproj'
arguments: '--output $(Build.ArtifactStagingDirectory)/publish --configuration Release'
enabled: true
- task: PublishPipelineArtifact@1
displayName: 'Publish function app output'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/publish'
artifact: 'drop'
publishLocation: 'pipeline'
enabled: true
- stage: Development
displayName: 'Development'
jobs:
- deployment: DevelopmentAzure
displayName: 'Development Azure'
environment: 'Development'
#uses runtime expression
strategy:
runOnce:
deploy:
steps:
- template: 'deploy-template.yml@pipeline'
parameters:
entryTemplateName: MyArm.json
templateParametersName: MyArm.dev.parameters.json
deploymentResourceManagerConnection: '$(Azure.NonProd.ResourceManagerConnection)'
deploymentSubscriptionIdentifier: '$(Azure.NonProd.SubscriptionId)'
resourceManagerConnection: '$(Azure.Dev.ResourceManagerConnection)'
subscriptionIdentifier: '$(Azure.Dev.SubscriptionId)'
resourceGroupName: '$(Resource_Group)'
outputVariablePrefix: AzureDeployment
- deployment: DevelopmentFunctions
displayName: 'DevelopmentFunctions'
environment: 'Development'
dependsOn: DevelopmentAzure
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
inputs:
azureSubscription: 'ServiceConnection-XXXXX-DevTest'
appType: 'functionApp'
appName: 'XXX-xxx-dev-funcapp'
package: '$(Pipeline.Workspace)/drop/*.zip'
deploymentMethod: 'zipDeploy'
enabled: true
那么将它部署到测试环境的方法是什么。 我是否需要在同一个仓库中创建另一个具有不同触发器的 yaml 文件? 或同一 yaml 文件中的不同阶段,并在发生 UAT 分支更改时对阶段应用一些条件,然后仅部署到仅 UAT 阶段(而不是开发阶段)。
任何帮助表示赞赏! 提前致谢
您只需要添加另一个具有一些条件的阶段即可部署到测试环境。
通常,您可以设置一个多阶段管道,其中包含应用程序的主要流程,例如“构建”、“测试”和“部署”。 和发布管道一样,您也可以在同一管道中为每个部署环境设置一个阶段。
在您的情况下,如果您希望当 UAT 分支上发生新的更改时,可以触发部署到测试环境,您可以在测试环境的舞台上设置如下条件。
stages:
. . .
- stage: Test
displayName: 'Deploy to Test environment'
dependsOn: Build
condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/UAT'))
. . .
有关更多详细信息,您可以查看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.