[英]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.