部署时将Azure Function Runtime版本设置为〜1

问题描述

我有一个AzureDevOps管道,该管道使用以下ARM模板部署Azure功能

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {
        "functionAppCSName": {
            "type": "string"
        },"storageAccountName": {
            "type": "string"
        },"storageAccountType": {
            "type": "string","defaultValue": "Standard_lrs","Metadata": {
                "description": "Geo-replication type of Storage account"
            },"allowedValues": [
                "Standard_lrs","Standard_GRS","Standard_ZRS","Standard_RGRS"
            ]
        },"serverFarmsName": {
            "type": "string"
        },"appInsightsName": {
            "type": "string"
        },"appinsightResourceGroupName": {
            "type": "string"
        },"webURL": {
            "type": "string"
        },"vaultName": {
            "type": "string"
        },"sspVaultName": {
            "type": "string"
        },"marketplaceVaultName": {
            "type": "string"
        },"redisRgName": {
            "type": "string"
        },"redisName": {
            "type": "string"
        },"environment": {
            "type": "string"
        },"aadTenant": {
            "type": "string"
        },"aadClientId": {
            "type": "string"
        },"audience": {
            "type": "string"
        },"location": {
            "type": "string"
        }
    },"resources": [
        {
            "type": "Microsoft.Storage/storageAccounts","name": "[parameters('storageAccountName')]","location": "[parameters('location')]","apiVersion": "2019-04-01","sku": {
                "name": "[parameters('storageAccountType')]"
            },"kind": "StorageV2","properties": {
            }
        },{
            "type": "Microsoft.Web/sites","kind": "functionapp","name": "[parameters('functionAppCSName')]","apiVersion": "2016-08-01","dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts',parameters('storageAccountName'))]"
            ],"identity": {
                "type": "SystemAssigned"
            },"tags": {
            },"properties": {
                "httpsOnly": true,"enabled": true,"serverFarmId": "[resourceId('Microsoft.Web/serverfarms',parameters('serverFarmsName'))]","reserved": false,"siteConfig": {
                    "AlwaysOn": true,"ftpsstate": "disabled"
                },"clientAffinityEnabled": true,"clientCertEnabled": false,"hostNamesdisabled": false,"containerSize": 1536,"dailyMemoryTimeQuota": 0,"remoteDebuggingEnabled": false,"webSocketsEnabled": false
            },"resources": [
                {
                    "apiVersion": "2016-08-01","name": "appsettings","type": "config","dependsOn": [
                        "[resourceId('Microsoft.Web/Sites',parameters('functionAppCSName'))]"
                    ],"properties": {
                        "sspSYstem_keyvAULT_URI": "[concat('https://',parameters('sspvaultname'),'.vault.azure.net')]","ssp_keyvAULT_URI": "[concat('https://',parameters('vaultName'),"MP_keyvAULT_URI": "[concat('https://',parameters('marketplaceVaultName'),"AzureWebJobsstorage": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listKeys(parameters('storageAccountName'),'2019-06-01').keys[0].value)]","AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=',"FUNCTIONS_EXTENSION_VERSION": "~3","AzureWebJobsSecretStorageType": "Files","APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId(parameters('appinsightResourceGroupName'),'Microsoft.Insights/components',parameters('appInsightsName')),'2014-04-01').InstrumentationKey]","CacheConnectionString": "[concat(parameters('redisName'),'.redis.cache.windows.net,abortConnect=false,ssl=true,password=',listKeys(resourceId(parameters('redisRgName'),'Microsoft.Cache/Redis',parameters('redisName')),'2015-08-01').primaryKey)]","AssetCacheKey": "[parameters('environment')]"
                    }
                },{
                    "comments": "CORS allow origins *.","type": "Microsoft.Web/sites/config","name": "[concat(parameters('functionAppCSName'),'/web')]","properties": {
                        "cors": {
                            "allowedOrigins": [
                                "https://functions.azure.com","https://functions-staging.azure.com","https://functions-next.azure.com","[parameters('webURL')]","http://localhost:4200"
                            ]
                        }
                    },"dependsOn": [
                        "[concat('Microsoft.Web/sites/',parameters('functionAppCSName'))]","[concat('Microsoft.Storage/storageAccounts/',parameters('storageAccountName'))]"
                    ]
                },{
                    "type": "config","name": "logs",parameters('storageAccountName'))]"
                    ],"properties": {
                        "remoteDebuggingEnabled": false,"webSocketsEnabled": false,"applicationLogs": {
                            "fileSystem": {
                                "level": "Off"
                            },"azureTableStorage": {
                                "level": "Off","sasUrl": null
                            },"azureBlobStorage": {
                                "level": "Verbose","sasUrl": "url","retentionInDays": 7
                            },"httpLogs": {
                                "fileSystem": {
                                    "retentionInMb": 365,"retentionInDays": 365,"enabled": true
                                },"azureBlobStorage": {
                                    "sasUrl": "url","enabled": true
                                }
                            },"FailedRequestsTracing": {
                                "enabled": true
                            },"detailedErrorMessages": {
                                "enabled": true
                            }
                        }
                    }
                },{
                    "name": "[concat(parameters('functionAppCSName'),'/authsettings')]","dependsOn": [
                        "[resourceId('Microsoft.Web/sites',"properties": {
                        "enabled": true,"tokenStoreEnabled": true,"defaultProvider": "AzureActiveDirectory","clientId": "[parameters('aadClientId')]","issuer": "[concat('https://login.microsoftonline.com/',parameters('aadTenant'))]","allowedAudiences": [
                            "[parameters('audience')]"
                        ]
                    }
                }
            ]
        }
    ],"outputs": {
        "tenantID": {
            "type": "string","value": "[reference(resourceId('Microsoft.Web/sites',parameters('functionAppCSName')),'2020-06-01','Full').identity.tenantId]"
        },"objectId": {
            "type": "string",'Full').identity.principalId]"
        }
    }
}

如您所见,我通过执行以下操作来设置Function App的运行时版本

...
{
                    "apiVersion": "2016-08-01","AssetCacheKey": "[parameters('environment')]"
                    }
                }
...

问题是当功能被部署时,运行时版本始终设置为1〜,我修复它的唯一方法删除功能应用并再次重新部署,或者在管道上一次又一次地重新部署直到变成〜3。

这对我们来说实在令人沮丧,因为我们无法正确或顺利地进行部署。

关于ARM模板,我是否缺少某些东西?

解决方法

尝试将API版本更改为最新版本。这应该在所有正在创建的/ site资源上完成。

{
                    "apiVersion": "2020-06-01","name": "appsettings","type": "config","dependsOn": [
                        "[resourceId('Microsoft.Web/Sites',parameters('functionAppCSName'))]"
                    ],

始终可以在Microsoft Docs上查看最新版本