改进 CI/CD 的 Azure 数据工厂部署
Azure Data Factory deployments with improved CI/CD
我正在关注此处发布的为 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)?
直接回答你的问题:
不,没有单独的 DEV ADF,旧版和新版之间的唯一区别是您不再需要从协作分支手动单击发布。它的工作方式是你现在有一个构建管道,只要你的合作分支有更新(通过 PR)就会触发,一旦构建验证并生成工件,就会有一个发布管道将 ARM 模板部署到你的 DEV数据工厂。
以下是要显示的屏幕截图:
1,将此 package.json 文件添加到您的协作分支
{
"scripts":{
"build":"node node_modules/@microsoft/azure-data-factory-utilities/lib/index"
},
"dependencies":{
"@microsoft/azure-data-factory-utilities":"^0.1.5"
}
}
就像我一样:
2、创建 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 数据工厂全局参数页面中取消选中包含在 ARM 模板中:
您需要在协作分支中为每个 ADF 环境保存一个 globalParameters json 文件。该文件将在 Powershell 脚本中使用,以确保 globalParameter 存在于您的 ADF 中。
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 断开连接)
如果我能提供任何其他帮助,请告诉我!
我正在关注此处发布的为 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)?
直接回答你的问题:
不,没有单独的 DEV ADF,旧版和新版之间的唯一区别是您不再需要从协作分支手动单击发布。它的工作方式是你现在有一个构建管道,只要你的合作分支有更新(通过 PR)就会触发,一旦构建验证并生成工件,就会有一个发布管道将 ARM 模板部署到你的 DEV数据工厂。
以下是要显示的屏幕截图:
1,将此 package.json 文件添加到您的协作分支
{
"scripts":{
"build":"node node_modules/@microsoft/azure-data-factory-utilities/lib/index"
},
"dependencies":{
"@microsoft/azure-data-factory-utilities":"^0.1.5"
}
}
就像我一样:
2、创建 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 数据工厂全局参数页面中取消选中包含在 ARM 模板中:
您需要在协作分支中为每个 ADF 环境保存一个 globalParameters json 文件。该文件将在 Powershell 脚本中使用,以确保 globalParameter 存在于您的 ADF 中。
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 断开连接)
如果我能提供任何其他帮助,请告诉我!