能否通过AZ DevOps YAML脚本排除预生产Data Factory中的指定管道?
如何在预生产Azure Data Factory部署中排除指定管道
完全可行,你当前的脚本写法有误,以下是两种靠谱的实现方式:
方法一:通过ARM参数文件控制管道部署
ADF生成的ARM模板会为每个管道自动生成pipeline<管道名称>_enabled格式的参数(默认值为true),只需修改预生产环境的参数文件即可排除目标管道:
- 打开预生产参数文件
ARMTemplateParametersForFactory-Preprod.json - 找到对应"POC test pipeline"的参数(类似
"pipelinePOCtestpipeline_enabled": { "value": true }),将值改为false - 调整你的YAML部署脚本,移除错误的排除参数,正常执行部署即可:
steps: - task: AzurePowerShell@5 displayName: Deploy ADF inputs: azureSubscription: ****** ScriptType: InlineScript Inline: | New-AzResourceGroupDeployment -ResourceGroupName "******" -TemplateParameterFile "$(System.DefaultWorkingDirectory)/Preproduction/ARMTemplateParametersForFactory-Preprod.json" -TemplateFile "$(System.DefaultWorkingDirectory)/******/ARMTemplateForFactory.json" -factoryName "*******" -Mode "Incremental" azurePowerShellVersion: LatestVersion
Incremental模式下,enabled设为false的管道不会被部署到预生产环境。
方法二:在部署前过滤ARM模板中的管道资源
如果不想修改参数文件,可以在PowerShell脚本中直接修改ARM模板内容,移除目标管道后再部署:
steps: - task: AzurePowerShell@5 displayName: Deploy ADF (Exclude POC Pipeline) inputs: azureSubscription: ****** ScriptType: InlineScript Inline: | # 读取原始ARM模板 $templatePath = "$(System.DefaultWorkingDirectory)/******/ARMTemplateForFactory.json" $template = Get-Content $templatePath -Raw | ConvertFrom-Json # 过滤掉名为"POC test pipeline"的管道资源 $template.resources = $template.resources | Where-Object { $_.type -ne "Microsoft.DataFactory/factories/pipelines" -or $_.name -notmatch "POC test pipeline" } # 保存修改后的临时模板 $tempTemplatePath = "$(System.DefaultWorkingDirectory)/temp-ARMTemplate.json" $template | ConvertTo-Json -Depth 10 | Set-Content $tempTemplatePath # 执行部署 New-AzResourceGroupDeployment -ResourceGroupName "******" -TemplateParameterFile "$(System.DefaultWorkingDirectory)/Preproduction/ARMTemplateParametersForFactory-Preprod.json" -TemplateFile $tempTemplatePath -factoryName "*******" -Mode "Incremental" azurePowerShellVersion: LatestVersion
注意事项
- 使用Incremental模式时,排除的管道如果已存在于预生产环境,不会被删除,只是本次部署不会更新它;若要删除该管道,需改用Complete模式,但此模式会删除模板中未定义的所有ADF资源,需谨慎操作。
- 确保管道名称匹配准确,ARM模板中管道的
name字段通常是[concat(parameters('factoryName'), '/管道名称')],过滤时需对应匹配。
内容的提问来源于stack exchange,提问作者shankar2805
相关产品推荐
相关产品推荐

