在 ADF 中使用函数应用程序连接器 - 如何覆盖 CI-CD 中的参数?

Using Function app connector in ADF - How to override parameters in CI-CD?

我需要尽快解决 - 当我们将 Az 函数添加到开发 ADF 管道时,这是开发过程中的一个迟到的惊喜。

当您在 ADF V2 中使用函数应用程序时,当您生成 ARM 模板时,它不会像其他链接服务那样参数化关键引用。呃!

因此对于 CI/CD 场景,当我们部署时,我们现在有一个固定功能的应用程序引用。我们想要做的与其他链接服务相同 - 覆盖关键参数以指向函数的正确 Dev/UAT/生产环境版本。

我能想到使用 powershell 覆盖的肮脏黑客(powershell 是否支持 ADF 功能?不知道 - 一月份他们不支持)。

关于如何覆盖函数应用链接服务设置的任何其他想法?

关键参数在 typeProperties 下(假设功能键在 keyvault 中):

{"functionAppUrl:="https://xxx.azurewebsites.net"}
{"functionkey":{"store":{"referenceName"="xxxKeyVaultLS"}}}
{"functionkey":{"secretName"="xxxKeyName"}}

现在这些是从 UI 设置硬编码的 - 没有参数也没有默认值。

好的,终于回到了这里。

解决方案看起来很多,但其实很简单。

在我的 devops 版本中,我在部署了数据工厂 ARM 模板和用于部署的 powershell 任务之后创建了一个 Powershell 任务。ps1 "predeployment=$false" 设置有 运行(参见 ADF CI/CD here。)

我的 git 存储库中每个环境 (dev/uat/prod) 都有一个 json 文件(我实际上使用单独的 "common" 存储库来存储脚本ADF git 存储库及其在 DevOps 中的别名是“_Common”——您将在下面的脚本的 -File 参数中看到它。

用于替换已部署函数链接服务的 json 文件是 ADF 中函数链接服务 json 的副本,对于 DEV 如下所示:

(scripts/Powershell/dev.json)

{
    "name": "FuncLinkedServiceName",
    "type": "Microsoft.DataFactory/factories/linkedservices",
    "properties": {
        "annotations": [],
        "type": "AzureFunction",
        "typeProperties": {
            "functionAppUrl": "https://myDEVfunction.azurewebsites.net",
            "functionKey": {
                "type": "AzureKeyVaultSecret",
                "store": {
                    "referenceName": "MyKeyvault_LS",
                    "type": "LinkedServiceReference"
                },
                "secretName": "MyFunctionKeyInKeyvault"
            }
        },
        "connectVia": {
            "referenceName": "MyintegrationRuntime",
            "type": "IntegrationRuntimeReference"
        }
    }
}

...而 PROD 文件将是这样的:

(scripts/Powershell/prod.json)

{
    "name": "FuncLinkedServiceName",
    "type": "Microsoft.DataFactory/factories/linkedservices",
    "properties": {
        "annotations": [],
        "type": "AzureFunction",
        "typeProperties": {
            "functionAppUrl": "https://myPRODfunction.azurewebsites.net",
            "functionKey": {
                "type": "AzureKeyVaultSecret",
                "store": {
                    "referenceName": "MyKeyvault_LS",
                    "type": "LinkedServiceReference"
                },
                "secretName": "MyFunctionKeyInKeyvault"
            }
        },
        "connectVia": {
            "referenceName": "MyintegrationRuntime",
            "type": "IntegrationRuntimeReference"
        }
    }
}

然后在 devops 管道中,我使用如下所示的 Powershell 脚本块:

Set-AzureRMDataFactoryV2LinkedService -ResourceGroup "$(varRGName)" -DataFactoryName "$(varAdfName)" -Name "$(varFuncLinkedServiceName)" -File "$(System.DefaultWorkingDirectory)/_Common/Scripts/Powershell/$(varEnvironment).json" -Force

或阿兹

Set-AzDataFactoryV2LinkedService -ResourceGroupName "$(varRGName)" -DataFactoryName "$(varAdfName)" -Name "$(varFuncLinkedServiceName)" -DefinitionFile "$(System.DefaultWorkingDirectory)/_Common/Scripts/Powershell/Converter/$(varEnvironment).json" -Force

注:

  • $(varXxx) 在我的管道变量中定义,例如
    • varFuncLinkServiceName = FuncLinkedServiceName.
    • varEnvironment = "DEV"、"UAT"、"PROD" 取决于目标版本
  • 使用强制是因为链接服务必须已经存在于数据工厂 ARM 部署中,然后我们需要强制覆盖函数链接服务。

希望 MSFT 将发布一个使用参数的函数应用程序链接服务,但在那之前,这让我们继续推进发布管道。

HTH。马克.

更新: 添加了 AzureRM 命令的 Az cmdlet 版本并更改为 Set("New-Az..." 有效,但在新的 Az 中 - 只有 Set- for V2链接服务)。