【问题标题】:Azure Data Factory deployments with improved CI/CD具有改进的 CI/CD 的 Azure 数据工厂部署
【发布时间】:2021-09-23 05:21:56
【问题描述】:

我正在关注此处发布的针对 ADF 的新推荐 ci/cd 设置:https://docs.microsoft.com/en-us/azure/data-factory/continuous-integration-deployment-improvements

我不清楚的一个部分是,您现在是否需要一个额外的“开发”ADF 管道发布到的位置。

在旧模型下,您将在链接到 git 的 ADF 中进行开发工作,执行拉取请求以合并回协作分支,然后单击发布。这将发布到同一 ADF 中的 adf_publish 分支。

对于新模型,您是否有一个链接到 git 的 ADF,您可以像以前一样在其中进行开发工作 - 但管道是否部署到一个新的单独的“开发”ADF(未链接到 git)?

【问题讨论】:

    标签: azure-devops azure-data-factory azure-data-factory-2


    【解决方案1】:

    直接回答您的问题:

    不,没有单独的 DEV ADF,旧版和新版之间的唯一区别是您不再需要从协作分支手动单击发布。它的工作方式是您现在有一个构建管道,只要您的协作分支有更新(通过 PR)就会触发该构建管道,一旦构建验证并生成工件,就会有一个发布管道将 ARM 模板部署到您的 DEV数据工厂。

    以下是要显示的屏幕截图:

    1st,将此 package.json 文件添加到您的协作分支中

    {
        "scripts":{
            "build":"node node_modules/@microsoft/azure-data-factory-utilities/lib/index"
        },
        "dependencies":{
            "@microsoft/azure-data-factory-utilities":"^0.1.5"
        }
    }
    

    像我一样:

    2nd,创建yaml构建管道并从下面的脚本中编辑参数

    # Sample YAML file to validate and export an ARM template into a build artifact
    # Requires a package.json file located in the target repository
    
    trigger:
    - main #collaboration branch
    
    pool:
      vmImage: 'ubuntu-latest'
    
    steps:
    
    # Installs Node and the npm packages saved in your package.json file in the build
    
    - task: NodeTool@0
      inputs:
        versionSpec: '10.x'
      displayName: 'Install Node.js'
    
    - task: Npm@1
      inputs:
        command: 'install'
        workingDir: '$(Build.Repository.LocalPath)/<folder-of-the-package.json-file>' #replace with the package.json folder
        verbose: true
      displayName: 'Install npm package'
    
    # Validates all of the Data Factory resources in the repository. You'll get the same validation errors as when "Validate All" is selected.
    # Enter the appropriate subscription and name for the source factory.
    
    - task: Npm@1
      inputs:
        command: 'custom'
        workingDir: '$(Build.Repository.LocalPath)/<folder-of-the-package.json-file>' #replace with the package.json folder
        customCommand: 'run build validate $(Build.Repository.LocalPath) /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testResourceGroup/providers/Microsoft.DataFactory/factories/yourFactoryName'
      displayName: 'Validate'
    
    # Validate and then generate the ARM template into the destination folder, which is the same as selecting "Publish" from the UX.
    # The ARM template generated isn't published to the live version of the factory. Deployment should be done by using a CI/CD pipeline. 
    
    - task: Npm@1
      inputs:
        command: 'custom'
        workingDir: '$(Build.Repository.LocalPath)/<folder-of-the-package.json-file>' #replace with the package.json folder
        customCommand: 'run build export $(Build.Repository.LocalPath) /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testResourceGroup/providers/Microsoft.DataFactory/factories/yourFactoryName "ArmTemplate"'
      displayName: 'Validate and Generate ARM template'
    
    # Publish the artifact to be used as a source for a release pipeline.
    
    - task: PublishPipelineArtifact@1
      inputs:
        targetPath: '$(Build.Repository.LocalPath)/<folder-of-the-package.json-file>/ArmTemplate' #replace with the package.json folder
        artifact: 'ArmTemplates'
        publishLocation: 'pipeline'
    

    每次协作分支发生更改时,都应该运行此构建。

    第三,使用构建工件(ARM 模板和参数文件)创建将部署到 DEV ADF 的发布管道

    任务详情:

    不要忘记在构建 ADF 时设置持续部署触发器。

    这就是它的全部内容,不再单击那个讨厌的发布按钮,而是您必须手动输入覆盖参数...您赢了一些,也输了一些......

    编辑:

    我发现如果您的 ARM 模板中包含全局参数,则会出现问题,如果指定了它们,当您部署到 DEV ADF 时,它将断开您的工厂与 Azure DevOps Git 的连接。为避免这种情况,您可以通过 PostDeploy powershell 脚本添加全局参数。

    以下是执行此操作的步骤:

    1. 确保在 Azure 数据工厂全局参数页面中未选中包含在 ARM 模板中:

    您需要在协作分支中为 ADF 的每个环境保存一个 globalParameters json 文件。此文件将在 Powershell 脚本中使用,以确保您的 ADF 中存在 globalParameter。

    2. 创建 Powershell 脚本文件并将其保存在您的协作分支中,以便可以通过 Az Powershell 任务在发布中使用它。

    param
    (
        [parameter(Mandatory = $true)] [String] $globalParametersFilePath,
        [parameter(Mandatory = $true)] [String] $resourceGroupName,
        [parameter(Mandatory = $true)] [String] $dataFactoryName
    )
    
    Import-Module Az.DataFactory
    
    $newGlobalParameters = New-Object 'system.collections.generic.dictionary[string,Microsoft.Azure.Management.DataFactory.Models.GlobalParameterSpecification]'
    
    Write-Host "Getting global parameters JSON from: " $globalParametersFilePath
    $globalParametersJson = Get-Content $globalParametersFilePath
    
    Write-Host "Parsing JSON..."
    $globalParametersObject = [Newtonsoft.Json.Linq.JObject]::Parse($globalParametersJson)
    
    foreach ($gp in $globalParametersObject.GetEnumerator()) {
        Write-Host "Adding global parameter:" $gp.Key
        $globalParameterValue = $gp.Value.ToObject([Microsoft.Azure.Management.DataFactory.Models.GlobalParameterSpecification])
        $newGlobalParameters.Add($gp.Key, $globalParameterValue)
    }
    
    $dataFactory = Get-AzDataFactoryV2 -ResourceGroupName $resourceGroupName -Name $dataFactoryName
    $dataFactory.GlobalParameters = $newGlobalParameters
    
    Write-Host "Updating" $newGlobalParameters.Count "global parameters."
    
    Set-AzDataFactoryV2 -InputObject $dataFactory -Force
    

    3. 确保发布管道中有一个 Az Powershell 任务,以使用给定参数运行 PostDeployment powershell 脚本。

    如果所有这些设置正确,那么您应该有一个为 ADF 构建的完全自动化的 CI/CD 流程(并且它不应该断开您与 Git 的连接)

    如果我能提供任何其他帮助,请告诉我!

    【讨论】:

    • 感谢您的详细解答。您所描述的是我目前的设置方式 - 基本上是这里概述的“当前 CI/CD 工作流程”:docs.microsoft.com/en-us/azure/data-factory/…。我正在考虑实施此处概述的“新 CI/CD 工作流程”:docs.microsoft.com/en-us/azure/data-factory/…。这种新的 CI/CD 流程无需手动单击“发布”按钮并从管道内发布到 Dev。
    • 哦,我明白了,抱歉我误解了。不过那很酷,我知道我已经看到了一些关于自动发布的东西。看起来唯一的区别是现在可以有一个自动构建任务来生成 ADF 工件(而不是拥有 Azure DevOps Repo 工件),然后这可以在新构建可用时触发向 DEV ADF 的发布。所以实际上它是完全自动化的 CI/CD 过程。这太棒了,并且允许您以相同的方式部署到每个环境。谢谢你,你在帮助我学习。
    • 我将编辑我的答案以反映,并在我实施这个新解决方案时举例说明。
    • 感谢您抽出宝贵时间试用并更新您的原始答案。我刚刚试了一下,但它并没有像我预期的那样工作。让我概述一下我的步骤...我将我的 ADF_DEV 工厂链接到 git。我在那里创建了一个功能分支并进行了一些编辑。我现在向我的主分支发出拉取请求。这是我的构建管道的开始。该构建管道验证并构建 ARM 文件。然后我在部署中使用 ARM 文件。我将 ARM 模板部署到 ADF_DEV 工厂。当我打开 ADF_DEV 时,它已更新。但是现在它没有连接到git。这不可能。
    • 我发现问题是因为我们(可能)都在我们的 ARM 模板中包含了全局参数,我已经更新了我的答案以通过 Az Powershell 自动创建全局参数,这很简单。我现在为我们的 EDW ADF 提供了一个完全自动化的 CI/CD 流程。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 2020-11-02
    • 1970-01-01
    • 2021-05-20
    相关资源
    最近更新 更多