使用改进的CI/CD进行Azure数据工厂部署 [英] Azure Data Factory deployments with improved CI/CD

查看:10
本文介绍了使用改进的CI/CD进行Azure数据工厂部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循此处发布的为ADF设置的新建议CI/CD:https://docs.microsoft.com/en-us/azure/data-factory/continuous-integration-deployment-improvements

有一节我不太清楚,那就是您现在是否需要管道发布到的其他&q;dev;adf。

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

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

推荐答案

直接回答您的问题:

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

以下是显示的屏幕截图:

首先,将此Package.json文件添加到您的协作分支

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

像我一样:

第二步,创建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'

每次更改您的协作分支时,都应运行此生成。

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

任务详细信息:

不要忘记在ADF的内部版本上设置连续部署触发器。

仅此而已,不再单击令人讨厌的发布按钮,而是必须手动输入覆盖参数...你有得也有失...

编辑:

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

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

1. 确保在您的Azure Data Factory全局参数页面中取消选中包括在ARM模板中:

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

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任务,以便使用给定的参数运行部署后PowerShell脚本。

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

如果我还能帮上什么忙,请告诉我!

这篇关于使用改进的CI/CD进行Azure数据工厂部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆