Deployment 如何使用YAML文件在Azure Devops中部署到不同的环境
你能帮我做下面的事吗 我正在构建Azure Function app V3,并使用Azure Devops YAML管道来构建和部署Azure Function app和ARM infra到开发环境。现在我想将其部署到UAT。我不知道如何使用YAML获得不同的环境。 请找到我正在使用的Deployment 如何使用YAML文件在Azure Devops中部署到不同的环境,deployment,azure-devops,continuous-integration,yaml,continuous-deployment,Deployment,Azure Devops,Continuous Integration,Yaml,Continuous Deployment,你能帮我做下面的事吗 我正在构建Azure Function app V3,并使用Azure Devops YAML管道来构建和部署Azure Function app和ARM infra到开发环境。现在我想将其部署到UAT。我不知道如何使用YAML获得不同的环境。 请找到我正在使用的azure pipeline.yml文件 name: $(Build.DefinitionName)-$(Date:yyyyMMdd)$(Rev:.r) trigger: - dev resources:
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
那么,将其部署到测试环境的方法是什么呢。我是否需要在同一个repo中创建另一个具有不同触发器的yaml文件?或在同一yaml文件中的不同阶段,并在UAT分支发生更改时对阶段应用某些条件,然后仅部署到UAT阶段(而不是开发阶段)
感谢您的帮助!!提前感谢您只需要添加另一个阶段,其中包含一些部署到测试环境的条件 通常,您可以设置一个多阶段管道,其中包含应用程序的主要流程,例如“构建”、“测试”和“部署”。和发布管道一样,您还可以在同一管道中为每个部署环境设置阶段 在您的情况下,如果您希望在UAT分支上发生新的更改时,可以触发部署到测试环境,您可以在测试环境的阶段上设置如下条件
阶段:
. . .
-阶段:测试
displayName:“部署到测试环境”
德彭森:建造
条件:and(successed(),eq(变量['build.sourceBranch'],'refs/heads/UAT'))
. . .
有关更多详细信息,请参见: