【问题标题】:How to deploy to different environment in Azure Devops using YAML file如何使用 YAML 文件部署到 Azure Devops 中的不同环境
【发布时间】:2021-03-17 21:49:53
【问题描述】:

您能帮我解决以下问题吗?

我正在构建 Azure Function app V3 并使用 Azure Devops YAML 管道构建 Azure Function app 和 ARM 基础架构并将其部署到开发环境。现在我想将其部署到 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 阶段(不是开发阶段)。

感谢任何帮助!提前致谢

【问题讨论】:

    标签: deployment azure-devops continuous-integration yaml continuous-deployment


    【解决方案1】:

    您只需要添加一个具有一些条件的阶段即可部署到测试环境。

    通常,您可以设置包含应用程序主要流程的多阶段管道,例如“构建”、“测试”和“部署”。和发布管道一样,您也可以在同一管道中为每个部署环境设置一个阶段。

    在您的情况下,如果您希望当 UAT 分支发生新的更改时,可以触发部署到测试环境,您可以在测试环境的舞台上设置如下条件。

    stages:
    . . .
    - stage: Test 
      displayName: 'Deploy to Test environment'
      dependsOn: Build
      condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/UAT'))
    . . .
    

    更多详情可以看:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 2020-12-02
      • 2021-02-27
      • 2020-01-25
      • 1970-01-01
      • 1970-01-01
      • 2021-10-19
      相关资源
      最近更新 更多