Share via


範例部署前和部署後指令碼

適用於:Azure Data Factory Azure Synapse Analytics

提示

試用 Microsoft Fabric 中的 Data Factory,這是適用於企業的全方位分析解決方案。 Microsoft Fabric 涵蓋從資料移動到資料科學、即時分析、商業智慧和報告的所有項目。 了解如何免費啟動新的試用版

下列範例將示範如何使用預先部署後指令碼,搭配 Azure Data Factory 中的持續整合和傳遞。

安裝 Azure PowerShell

依照如何安裝和設定 Azure PowerShell中的指示,安裝最新的 Azure PowerShell 模組。

警告

請務必在 ADO 工作中使用 PowerShell Core 執行指令碼

部署前後指令碼

在發行程序期間 (CICD) 停止/啟動觸發程序和更新全域參數的指令碼範例位於 Azure Data Factory 官方 GitHub 頁面中。

注意

在持續整合與持續傳遞期間,如果您只要關閉/開啟已修改的觸發程序,而不是關閉/開啟所有觸發程序,請使用 PrePostDeploymentScript.Ver2.ps1

指令碼執行和參數

下列範例指令碼可用來在部署前停止觸發程序,且之後重新啟動觸發程序。 此指令碼也包含可將已移除的資源刪除的程式碼。 將指令碼儲存在 Azure DevOps Git 存放庫中,並透過使用最新版的 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 部署專案。

Azure PowerShell task

指令碼執行和參數 - 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: ../