你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
适用于:
Azure Data Factory
Azure Synapse Analytics
提示
Microsoft Fabric 中的 Data Factory 是下一代 Azure Data Factory,具有更加简化的架构、内置人工智能和新功能。 如果不熟悉数据集成,请从Fabric数据工厂开始。 现有 ADF 工作负载可以升级到 Fabric,以跨数据科学、实时分析和报告访问新功能。
以下示例演示如何在 Azure Data Factory 中使用部署前和部署后脚本进行持续集成和交付。
安装Azure PowerShell
请按照 如何安装和配置 Azure PowerShell 中的说明安装最新的 Azure PowerShell 模块。
警告
确保在 ADO 任务中使用 PowerShell Core 来运行脚本
部署前和部署后脚本
在发布过程中停止/启动触发器和更新全局参数的示例脚本位于 Azure Data Factory 官方GitHub页。
注意
如果只想在 CI/CD 期间关闭/打开已修改的触发器,而不是关闭/打开所有触发器,可以使用 PrePostDeploymentScript.Ver2.ps1。
脚本执行和脚本参数
以下示例脚本可用于在部署之前停止触发器,并在部署之后重启触发器。 此脚本还包括用于删除已移除资源的代码。 将脚本保存在Azure DevOps git 存储库中,并通过最新Azure PowerShell版本Azure PowerShell任务引用该脚本。
在运行部署前脚本时,需在“脚本参数”字段中指定以下参数的变体。
-armTemplate "$(System.DefaultWorkingDirectory)/<your-arm-template-location>" -ResourceGroupName <your-resource-group-name> -DataFactoryName <your-data-factory-name> -predeployment $true -deleteDeployment $false
在运行部署后脚本时,需在“脚本参数”字段中指定以下参数的变体。
-armTemplate "$(System.DefaultWorkingDirectory)/<your-arm-template-location>" -ResourceGroupName <your-resource-group-name> -DataFactoryName <your-data-factory-name> -predeployment $false -deleteDeployment $true
注意
-deleteDeployment 标志用于指定从 ARM 的部署历史记录中删除 ADF 部署条目。
脚本执行和参数 - YAML 管道
以下 YAML 代码会执行可用于在部署之前停止触发器,并在部署之后重启触发器的脚本。 此脚本还包括用于删除已移除资源的代码。 如果遵循新 CI/CD 流中所述的步骤,则此脚本会作为通过 npm 发布包创建的工件的一部分导出。
停止 ADF 触发器
- task: AzurePowerShell@5
displayName: Stop ADF Triggers
inputs:
scriptType: 'FilePath'
ConnectedServiceNameARM: AzureDevServiceConnection
scriptPath: ../ADFTemplates/PrePostDeploymentScript.ps1
ScriptArguments: -armTemplate "<your-arm-template-location>" -ResourceGroupName <your-resource-group-name> -DataFactoryName <your-data-factory-name> -predeployment $true -deleteDeployment $false
errorActionPreference: stop
FailOnStandardError: False
azurePowerShellVersion: 'LatestVersion'
pwsh: True
workingDirectory: ../
启动 ADF 触发器
- task: AzurePowerShell@5
displayName: Start ADF Triggers
inputs:
scriptType: 'FilePath'
ConnectedServiceNameARM: AzureDevServiceConnection
scriptPath: ../ADFTemplates/PrePostDeploymentScript.ps1
ScriptArguments: -armTemplate "<your-arm-template-location>" -ResourceGroupName <your-resource-group-name> -DataFactoryName <your-data-factory-name>-predeployment $false -deleteDeployment $true
errorActionPreference: stop
FailOnStandardError: False
azurePowerShellVersion: 'LatestVersion'
pwsh: True
workingDirectory: ../