Azure devops 如何通过部署作业以Azure YAML管道中的环境为目标?

Azure devops 如何通过部署作业以Azure YAML管道中的环境为目标?,azure-devops,continuous-integration,yaml,azure-pipelines,continuous-deployment,Azure Devops,Continuous Integration,Yaml,Azure Pipelines,Continuous Deployment,目标 使用部署作业通过Azure YAML将管道工件部署到环境中的VM资源 YAML 这是我正在使用的完整YAML管道。通过这个YAML文件,我希望实现以下目标 建造 试验 发布工件 将工件部署到RO-TST环境中的资源(VM的内部部署) 结果 第1步到第3步的效果很好。在步骤4(部署作业)中,复制文件任务未在RO-TST环境中注册的资源代理上运行。但是,复制文件任务将在托管代理上运行 作业初始化: Starting: Initialize job Agent name: 'Hosted Ag

目标

使用部署作业通过Azure YAML将管道工件部署到环境中的VM资源

YAML

这是我正在使用的完整YAML管道。通过这个YAML文件,我希望实现以下目标

  • 建造
  • 试验
  • 发布工件
  • 将工件部署到RO-TST环境中的资源(VM的内部部署)

  • 结果

    第1步到第3步的效果很好。在步骤4(部署作业)中,复制文件任务未在RO-TST环境中注册的资源代理上运行。但是,复制文件任务将在托管代理上运行

    作业初始化:

    Starting: Initialize job
    Agent name: 'Hosted Agent'
    Agent machine name: 'fv-az686'
    Current agent version: '2.168.2'
    Operating System
    Virtual Environment
    Current image version: '20200517.1'
    Agent running as: 'VssAdministrator'
    Prepare build directory.
    Set build variables.
    Download all required tasks.
    Downloading task: DownloadPipelineArtifact (1.2.4)
    Downloading task: CopyFiles (2.164.0)
    Downloading task: CmdLine (2.164.0)
    Checking job knob settings.
       Knob: AgentToolsDirectory = C:/hostedtoolcache/windows Source: ${AGENT_TOOLSDIRECTORY} 
       Knob: AgentPerflog = c:\vsts\perflog Source: ${VSTS_AGENT_PERFLOG} 
    Finished checking job knob settings.
    Start tracking orphan processes.
    Finishing: Initialize job
    
    Starting: Initialize job
    Agent name: 'APP1234'
    Agent machine name: 'APP1234'
    Current agent version: '2.168.2'
    Agent running as: 'APP1234$'
    Prepare build directory.
    Set build variables.
    Download all required tasks.
    Checking job knob settings.
    Finished checking job knob settings.
    Start tracking orphan processes.
    Finishing: Initialize job
    
    当我以环境中的特定资源(RO-TST.APP1234)为目标时,复制文件任务会在资源代理上运行。这是通过将部署作业中的环境值更改为RO-TST.APP1234来实现的

    - stage: DeployTst
      displayName: Deploy to TST
      jobs:
      - deployment: Deployment
        environment: RO-TST.APP1234
        strategy:
          runOnce:
            deploy:
              steps:
              - task: CopyFiles@2
                inputs:
                  SourceFolder: '$(Pipeline.Workspace)'
                  Contents: '**'
                  TargetFolder: 'D:\Application\'
    
    作业初始化:

    Starting: Initialize job
    Agent name: 'Hosted Agent'
    Agent machine name: 'fv-az686'
    Current agent version: '2.168.2'
    Operating System
    Virtual Environment
    Current image version: '20200517.1'
    Agent running as: 'VssAdministrator'
    Prepare build directory.
    Set build variables.
    Download all required tasks.
    Downloading task: DownloadPipelineArtifact (1.2.4)
    Downloading task: CopyFiles (2.164.0)
    Downloading task: CmdLine (2.164.0)
    Checking job knob settings.
       Knob: AgentToolsDirectory = C:/hostedtoolcache/windows Source: ${AGENT_TOOLSDIRECTORY} 
       Knob: AgentPerflog = c:\vsts\perflog Source: ${VSTS_AGENT_PERFLOG} 
    Finished checking job knob settings.
    Start tracking orphan processes.
    Finishing: Initialize job
    
    Starting: Initialize job
    Agent name: 'APP1234'
    Agent machine name: 'APP1234'
    Current agent version: '2.168.2'
    Agent running as: 'APP1234$'
    Prepare build directory.
    Set build variables.
    Download all required tasks.
    Checking job knob settings.
    Finished checking job knob settings.
    Start tracking orphan processes.
    Finishing: Initialize job
    
    我尝试过其他部署策略,如rolling和canary,但它们不适用于环境范围的目标。下面是Microsoft提供的有关部署作业的文档


    我知道您可以通过“经典”方法使用部署组,通过AzureDevOps中的发行版将CI与CD分开。但我真的很想在一个YAML文件中包含完整的CI-CD管道。那么,我是在部署作业的设置方式上遗漏了什么,还是无法通过环境在YAML中定位多个资源?

    因此,我终于找到了为什么我的YAML不能用于部署作业。多亏了VM资源文档中给出的示例

    这是修改后的YAML,我在其中添加了属性名称、resourceType和标记。我已经在我的环境资源上贴了标签,所以效果很好。在运行管道之后,通过标记控制台将工件部署到RO-TST中的所有资源

    - stage: DeployTst
      displayName: Deploy to TST
      jobs:
      - deployment: Deployment
        environment: 
          name: RO-TST
          resourceType: VirtualMachine
          tags: Console
        strategy:
          runOnce:
            deploy:
              steps:
              - task: CopyFiles@2
                inputs:
                  SourceFolder: '$(Pipeline.Workspace)'
                  Contents: '**'
                  TargetFolder: 'D:\Application\'
    

    感谢您在这里分享您的解决方案,请接受您的解决方案好吗?因此,它将有助于其他成员谁得到同样的问题,找到解决办法容易。祝您愉快:)@HughLin MSFT,yaml管道的文档质量需要提高。