Azure 管道不适用于生产

Posted

技术标签:

【中文标题】Azure 管道不适用于生产【英文标题】:Azure pipeline not working for production 【发布时间】:2021-12-24 03:37:52 【问题描述】:

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

    amit-dev - 用于开发环境。 amit-tst - 用于测试环境。 amit-prd - 用于 PRD 环境

test 和 dev 不需要批准,但 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 部署会出错,而相同的代码行可用于测试和开发环境而没有任何问题。

【问题讨论】:

这就是您应该使用模板的原因:您的“prd”阶段显然对csmFilecsmParametersFile 使用了不同的值。这与审批无关。 不,事实并非如此 【参考方案1】:

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

【讨论】:

以上是关于Azure 管道不适用于生产的主要内容,如果未能解决你的问题,请参考以下文章

Azure iOS 推送通知在生产模式下未收到?

生产推送通知 .p12 生产证书不适用于企业分发应用程序(应用商店之外)

推送通知不适用于生产

推送通知不适用于 iphone 中的生产证书?

Jquery 验证不适用于登台和生产系统

Response.Write 不适用于生产 [重复]