【问题标题】:CI pipeline fails even though it is doing what its supposed toCI管道失败,即使它正在做它应该做的事情
【发布时间】:2020-12-09 04:18:58
【问题描述】:

首先让我说我刚开始使用 Azure,绝不是专业人士,并且一直在到处遵循指南。因此,我通过在我自己的 Azure DevOps 订阅中部署 this repo 来关注 this 文章,在我更改资源组、订阅和函数名称后,我构建并运行 CI 管道,然后在“部署 Azure资源”我会得到this 错误,即使在管道退出后,资源是按照它应该的方式创建的,我还注意到如果我第二次重新运行相同的管道,它工作得很好,这令人困惑。这是我修改后的 YAML 模板

name: DeployAzureFunction
variables:
  FunctionAppName: 'test'
  AzureConnection: 'DevOps-Test'
  ResourcegGroupName: 'test'

trigger:
  branches:
    include:
    - '*'  # must quote since "*" is a YAML reserved character; we want a string



stages:

- stage: Build
  jobs:
  - job: Test_FA
    pool:
      vmImage: windows-2019
    steps:
    - task: AzureResourceGroupDeployment@2
      displayName: 'Test ARM Deployment'
      inputs:
        azureSubscription: $(AzureConnection)
        resourceGroupName: $(ResourcegGroupName)
        location: 'East US 2'
        csmFile: Deployment/azuredeploy.json
        deploymentMode: Validation
    - powershell: |
       Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
       Install-Module -Name Pester -Force -Scope CurrentUser -SkipPublisherCheck
       Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
      displayName: 'Install Pester and import module'
   
  - job: Build_FA
    pool:
      vmImage: windows-2019
    steps:
    - task: ArchiveFiles@2
      displayName: 'Archive FunctionApp'
      inputs:
        rootFolderOrFile: FunctionApp
        includeRootFolder: false
        archiveFile: '$(System.DefaultWorkingDirectory)/zip/FunctionApp.zip'
    - task: PublishPipelineArtifact@0
      inputs:
        artifactName: 'zip'
        targetPath: '$(System.DefaultWorkingDirectory)/zip'

- stage: Deploy
  jobs:
  - job: Deploy_ARM
    pool:
      vmImage: windows-2019
    steps:
    - task: AzureResourceGroupDeployment@2
      displayName: 'Deploy Azure Resources'
      continueOnError: true
      inputs:
        azureSubscription: $(AzureConnection)
        resourceGroupName: $(ResourcegGroupName)
        location: 'East US 2'
        csmFile: Deployment/azuredeploy.json
        csmParametersFile: Deployment/azuredeploy.parameters.json
        overrideParameters: '-functionAppName $(FunctionAppName)'
        deploymentMode: Incremental
        deploymentOutputs: DeploymentOutput

这是未修改的 azuredeploy.json,我认为是导致问题的原因,但不确定原因

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "functionAppName": {
            "type": "string",
            "defaultValue": "[uniqueString(resourceGroup().id)]",
            "metadata": {
                "description": "Specify the name of the function application"
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Specify the location for the function application resources"
            }
        }
    },
    "variables": {
        "hostingPlanName": "[parameters('functionAppName')]",
        "storageacccount": "[toLower(parameters('functionAppName'))]",
        "storageAccountName": "[concat('storage', variables('storageacccount'))]"
    },
    "resources": [
        {
            "apiVersion": "2017-06-01",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[variables('storageAccountName')]",
            "location": "[parameters('location')]",
            "kind": "Storage",
            "sku": {
                "name": "Standard_LRS"
            }
        },
        {
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2018-11-01",
            "name": "[variables('hostingPlanName')]",
            "location": "[parameters('location')]",
            "sku": {
                "name": "Y1",
                "tier": "Dynamic",
                "size": "Y1",
                "family": "Y",
                "capacity": 0
            },
            "properties": {
                "name": "[variables('hostingPlanName')]"
            }
        },
        {
            "name": "[parameters('functionAppName')]",
            "type": "Microsoft.Web/sites",
            "apiVersion": "2018-02-01",
            "location": "[parameters('location')]",
            "kind": "functionapp",
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]",
                "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
                "[resourceId('microsoft.insights/components/', parameters('functionAppName'))]"
            ],
            "identity": {
                "type": "SystemAssigned"
            },
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "powershell"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2017-06-01').keys[0].value)]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~2"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference(resourceId('microsoft.insights/components/', parameters('functionAppName')), '2018-05-01-preview').InstrumentationKey]"
                        },
                        {
                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')),'2017-06-01').keys[0].value)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTSHARE",
                            "value": "[toLower(parameters('functionAppName'))]"
                        }
                    ]
                },
                "name": "[parameters('functionAppName')]",
                "clientAffinityEnabled": false,
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]"
            }
        },
        {
            "apiVersion": "2015-05-01",
            "name": "[parameters('functionAppName')]",
            "type": "Microsoft.Insights/components",
            "kind": "Web",
            "location": "[parameters('location')]",
            "tags": {
                "[concat('hidden-link:', resourceId('Microsoft.Web/sites/', parameters('functionAppName')))]": "Resource"
            },
            "properties": {
                "ApplicationId": "[parameters('functionAppName')]",
                "Application_Type": "web"
            }
        }
    ],
    "outputs": {
        "principalId": {
            "type": "string",
            "value": "[reference(concat(resourceId('Microsoft.Web/sites/', parameters('functionAppName')), '/providers/Microsoft.ManagedIdentity/Identities/default'), '2015-08-31-PREVIEW').principalId]"
        }
    }
}

如果有人能帮我弄清楚为什么我在第一次运行时会出现这个错误,我将不胜感激,谢谢!

【问题讨论】:

    标签: json azure azure-devops yaml azure-pipelines


    【解决方案1】:

    资源已创建,但部署操作失败,因为计算输出变量时出现问题。

    很可能是因为您尝试访问应用服务的服务主体 ID 的方式。 '/providers/Microsoft.ManagedIdentity/Identities/default' 部分。

    你可能想要这样的东西:

    [reference(resourceId('Microsoft.Web/sites', parameters('functionAppName')), '2016-08-01', 'Full').identity.principalId]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-28
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      相关资源
      最近更新 更多