Azure Devops YAML多阶段管道工件问题

时间:2019-10-24 08:06:47

标签: azure azure-devops azure-pipelines

我的Azure Devops YAML多阶段管道在进行ARM部署时给我一个错误。问题是从构建中下载工件。在这里看到错误:

Error

我看起来好像没有在下载作业之前在作业中下载工件。区别在于生产部署需要得到批准,因此它在-deployment内部,而不是-job。

在此处查看代码:

- stage: Deploy_Prod
  dependsOn: Deploy_Acc
  # Only deploy when build is from master
  condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/master'))
  jobs:
  - deployment: 'Deploy_Prod'
    pool:
      vmImage: 'ubuntu-latest'
    # Set envrironment for approval, see https://dev.azure.com/dept/DTNL%20-%20CBRE/_environments/5?view=resources
    environment: cbre_prod  
    strategy:
      runOnce:
        deploy:
          steps:
            # Download build artifact
            - download: current
              artifact: Templates

            # Deploy production infra
            - task: AzureResourceManagerTemplateDeployment@3
              displayName: 'Deploy production infrastructure'
              inputs:
                deploymentScope: 'Resource Group'
                ConnectedServiceName: '***'
                subscriptionName: '***'
                action: 'Create Or Update Resource Group'
                resourceGroupName: '***'
                location: 'West Europe'
                templateLocation: 'Linked artifact'
                csmFile: 'azuredeploy.json'
                csmParametersFile: 'azuredeploy-parameters-prod.json'
                deploymentMode: 'incremental'

有人知道如何在使用-deployment而不是-job的同时从多阶段管道下载工件吗?

带工作的工作版本,仅供参考:

  dependsOn: Deploy_Test
  # Only deploy when build is from master
  condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/master'))
  jobs:
  - job: 'Deploy_Acc'
    pool:
      vmImage: 'ubuntu-latest'

    steps:
      # Download build artifact
      - download: current
        artifact: Templates

      # Deploy acceptation infra
      - task: AzureResourceManagerTemplateDeployment@3
        displayName: 'Deploy acceptation infrastructure'
        inputs:
          deploymentScope: 'Resource Group'
          ConnectedServiceName: '***'
          subscriptionName: '***'
          action: 'Create Or Update Resource Group'
          resourceGroupName: '***-acc'
          location: 'West Europe'
          templateLocation: 'Linked artifact'
          csmFile: 'azuredeploy.json'
          csmParametersFile: 'azuredeploy-parameters-acc.json'
          deploymentMode: 'incremental' ```

2 个答案:

答案 0 :(得分:2)

我没有发现您的代码有任何问题。在创建工件时,您是否使用过“发布管道工件”?

Publish Pipeline Artifact

答案 1 :(得分:1)

documentation on deployment jobs建议您可能不需要指示它下载工件,它会自动发生?

deploy:用于运行部署应用程序的步骤。下载工件任务将仅自动注入到部署作业的部署挂钩中。要停止下载工件,请使用- download: none或通过指定“下载管道工件”任务来选择要下载的特定工件。