Azure 管道不适用于生产

Azure pipeline not working for production

我想使用 azure 管道部署 3 个服务总线资源。

  1. amit-dev - 用于开发环境。
  2. amit-tst - 用于测试环境。
  3. amit-prd - 适用于珠三角环境

测试和开发不需要审批,但珠三角部署需要审批。

我的管道能够毫无问题地部署开发和测试资源,它在 prd 部署时请求批准,但随后停止并显示错误消息:

Creating deployment parameters.
##[error]Check out the troubleshooting guide to see if your issue is addressed: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#troubleshooting
##[error]Error: Could not find any file matching the template file pattern
Finishing: AzureResourceManagerTemplateDeployment

这是我的管道代码。

trigger:
  branches:
    include:
      - main
      - release/*
      - feature/*
      - bug-fix/*

pool:
  vmImage: ubuntu-latest

stages:
  - stage: 'DevDeployStage'
    dependsOn: BuildStage
    condition: and(succeeded('BuildStage'), contains(variables['Build.SourceBranch'],'refs/heads/main'))
    variables:
    - group: common-kv-dev
    - group: common-dp-dev
    displayName: 'DevDeployStage'
    jobs: 
      - job:  DevDeployStageJob
        steps:
          - task: AzureResourceManagerTemplateDeployment@3
            inputs:
                deploymentScope: 'Resource Group'
                azureResourceManagerConnection: 'conn-to-RG'
                subscriptionId: '7777777-4444-4444-4444-222222222222'
                action: 'Create Or Update Resource Group'
                resourceGroupName: 'MY_RG'
                location: 'East US'
                templateLocation: 'Linked artifact'
                csmFile: '$(System.DefaultWorkingDirectory)/template.json'
                csmParametersFile: '$(System.DefaultWorkingDirectory)/parameters.json'
                overrideParameters: '-namespaces_amitbus_name amit-dev'
                deploymentMode: 'Incremental'

  - stage: 'tstDeployStage'
    dependsOn: BuildStage
    condition: and(succeeded('BuildStage'), contains(variables['Build.SourceBranch'],'refs/heads/main'))
    variables:
    - group: common-kv-dev
    - group: common-dp-dev
    displayName: 'tstDeployStage'
    jobs: 
      - job:  tstDeployStageJob
        steps:
          - task: AzureResourceManagerTemplateDeployment@3
            inputs:
                deploymentScope: 'Resource Group'
                azureResourceManagerConnection: 'conn-to-RG'
                subscriptionId: '7777777-4444-4444-4444-222222222222'
                action: 'Create Or Update Resource Group'
                resourceGroupName: 'MY_RG'
                location: 'East US'
                templateLocation: 'Linked artifact'
                csmFile: '$(System.DefaultWorkingDirectory)/template.json'
                csmParametersFile: '$(System.DefaultWorkingDirectory)/parameters.json'
                overrideParameters: '-namespaces_amitbus_name amit-tst'
                deploymentMode: 'Incremental'

  - stage: 'PrdDeployStage'
    dependsOn: BuildStage
    condition: and(succeeded('BuildStage'), contains(variables['Build.SourceBranch'],'refs/heads/main'))
    variables:
    - group: common-kv-dev
    - group: common-dp-dev
    displayName: 'PrdDeployStage'
    jobs: 
      - deployment: PrdDeployStageJobDeploment
        displayName: 'PrdDeployStageJob'
        pool:
          vmImage: ubuntu-latest
        environment: production
        strategy:
          runOnce:
            deploy:
              steps:
                - task: AzureResourceManagerTemplateDeployment@3
                  inputs:
                    deploymentScope: 'Resource Group'
                    azureResourceManagerConnection: 'conn-to-RG'
                    subscriptionId: '7777777-4444-4444-4444-222222222222'
                    action: 'Create Or Update Resource Group'
                    resourceGroupName: 'MY_RG'
                    location: 'East US'
                    templateLocation: 'Linked artifact'
                    csmFile: 'template.json'
                    csmParametersFile: 'parameters.json'
                    overrideParameters: '-namespaces_amitbus_name amit-prd'
                    deploymentMode: 'Incremental'

我不明白为什么 prd 部署会出错,而相同的代码行在测试和开发环境中没有任何问题。

作业和部署在本质上是不同的。默认情况下,作业将下载存储库,但部署不会。刚刚提到结帐:部署中的自我,它解决了我的问题。