適用於:
Azure Data Factory
Azure Synapse Analytics
提示
Data Factory in Microsoft Fabric 是下一代的 Azure Data Factory,擁有更簡單的架構、內建 AI 及新功能。 如果你是資料整合新手,建議先從 Fabric Data Factory 開始。 現有的 ADF 工作負載可升級至 Fabric,以存取資料科學、即時分析與報告等新能力。
注意
Synapse Analytics 也支援 CI/CD。 如需詳細資訊, 請參閱 Synapse Analytics CI/CD 檔 。
概觀
持續整合是指進行相關實作,以自動測試對您的程式碼基底所做的每項變更。 持續傳遞會盡早在持續整合過程中的測試之後,將變更推送到暫存或生產系統。
在 Azure Data Factory 中,CI/CD 指的是將資料工廠管線從一個環境(如開發、測試和生產環境)轉移到另一個環境。 Data Factory 使用 Azure Resource Manager 模板(ARM 模板)來儲存各種資料工廠實體的配置,例如管線、資料集和資料流。
有兩個建議的方法可將資料處理站升級至另一個環境:
- 透過 Data Factory 與 Azure Pipelines 的整合來自動化部署。
- 透過 Data Factory 使用者體驗整合與 Azure Resource Manager 手動上傳 ARM 範本。
欲了解更多資訊,請參閱持續整合與交付,Azure Data Factory。
本文著重於持續改善部署,以及 CI/CD 的自動發佈功能。
持續部署改進
自動發佈功能會從 Data Factory 使用者體驗中取得「驗證全部」和「匯出 ARM 範本」功能,並透過公開可用的 npm 套件 @microsoft/azure-data-factory-utilities,讓邏輯可供取用。 基於此原因,您可以使用程式設計方式來觸發這些動作,而不需要移至 Data Factory UI,並手動選取按鈕。 這項能力讓您的 CI/CD 管線擁有更真實的持續整合體驗。
注意
請務必使用版本 20.x 及其相容版本 Node.js 以避免因套件與舊版本不相容而產生的錯誤。
目前 CI/CD 流程
- 每位使用者都會在其私人分支中進行更改。
- 不允許推到主線。 使用者必須建立提取要求,才能進行變更。
- 使用者必須載入 Data Factory UI,然後選取 [發佈] 將變更部署至 Data Factory,並在發佈分支中產生 ARM 範本。
- DevOps 發行版本管線設定為建立新的發行版本,並在每次將新的變更推送至發佈分支時部署 ARM 範本。
手動步驟
在目前的 CI/CD 流程中,使用者體驗是建立 ARM 範本的媒介。 因此,使用者必須移至 Data Factory UI,然後手動選取 [發佈] 以啟動 ARM 範本產生,並將該範本放在發佈分支中。
新的 CI/CD 流程
- 每位使用者都會在其私人分支中進行更改。
- 不允許推到主線。 使用者必須建立提取要求,才能進行變更。
- Azure DevOps 管線建置會在每次對主線進行新提交時觸發。 這會驗證資源,並在驗證成功時產生 ARM 範本以作為成品。
- DevOps 發行版本管線設定為建立新發行版本,並在每次有新組建可用時部署 ARM 範本。
變更的項目為何?
- 你現在有一個使用 DevOps 建置管線的建置流程。
- 建置管線使用 ADFUtilities (
@microsoft/azure-data-factory-utilities) npm 套件,該套件驗證所有資源並產生 ARM 範本。 這些範本可以是獨立或已連結。 - 建置流程會驗證資料工廠資源,並產生 ARM 範本,取代資料工廠的使用者介面(發佈 按鈕)。
- DevOps 版本定義現在會消耗這個新的建置流程,而不是 Git 工件。
注意
您可以繼續使用現有機制 (即 adf_publish 分支),也可以使用新的流程。 兩者都支援。
套件概觀
套件中目前提供兩個命令:
- 匯出 ARM 範本
- 驗證
匯出 ARM 範本
執行 npm run build export <rootFolder> <factoryId> [outputFolder],以使用所指定資料夾的資源來匯出 ARM 範本。 此指令在產生 ARM 範本前也會執行驗證檢查。 這裡有一個使用名為 testResourceGroup 的資源群組的範例:
npm run build export C:\DataFactories\DevDataFactory /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testResourceGroup/providers/Microsoft.DataFactory/factories/DevDataFactory ArmTemplateOutput
-
RootFolder是必要欄位,可代表 Data Factory 資源所在的位置。 -
FactoryId是一個必須欄位,代表資料工廠資源 ID 格式為/subscriptions/<subId>/resourceGroups/<rgName>/providers/Microsoft.DataFactory/factories/<dfName>。 -
OutputFolder是選用參數,可指定要儲存所產生 ARM 範本的相對路徑。
現在只能停止/啟動更新的觸發器功能,並已合併到前一個指令中。
注意
產生的 ARM 範本不會發佈至處理站的即時版本。 部署應該使用 CI/CD 管線來完成。
驗證
執行 npm run build validate <rootFolder> <factoryId> 以驗證所指定資料夾的所有資源。 以下是範例:
npm run build validate C:\DataFactories\DevDataFactory /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testResourceGroup/providers/Microsoft.DataFactory/factories/DevDataFactory
-
RootFolder是必要欄位,可代表 Data Factory 資源所在的位置。 -
FactoryId是一個必須欄位,代表資料工廠資源 ID 格式為/subscriptions/<subId>/resourceGroups/<rgName>/providers/Microsoft.DataFactory/factories/<dfName>。
建立 Azure 管線
雖然 NPM 套件可以用多種方式使用,但其中一個主要好處是透過 Azure Pipelines 來使用。 每次合併到協作分支時,都可以觸發一個管線,先驗證所有程式碼,然後將 ARM 範本匯出成一個可被發佈管線使用的完整 建置產物 。 它和目前的 CI/CD 流程不同之處在於,你會 把發佈流程指向這個產物,而不是現有 adf_publish 的分支。
遵循下列步驟以開始使用:
開啟一個Azure DevOps專案,然後到 Pipelines。 選取新建管線。
選取您想要在其中儲存管線 YAML 指令碼的存放庫。 把它存到和 Data Factory 資源同一個倉庫裡的建置資料夾裡。 請確定存放庫中有包含套件名稱的 package.json 檔案,如下列範例所示:
{ "scripts":{ "build":"node node_modules/@microsoft/azure-data-factory-utilities/lib/index" }, "dependencies":{ "@microsoft/azure-data-factory-utilities":"^1.0.0" } }選取 [入門管線]。 如果您已上傳或合併 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: UseNode@1 inputs: version: '20.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. Either of the "Validate" or "Validate and Generate ARM template" options are required to perform validation. Running both is unnecessary. - 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)/<Root-folder-from-Git-configuration-settings-in-ADF> /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/<Your-ResourceGroup-Name>/providers/Microsoft.DataFactory/factories/<Your-Factory-Name>' 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)/<Root-folder-from-Git-configuration-settings-in-ADF> /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/<Your-ResourceGroup-Name>/providers/Microsoft.DataFactory/factories/<Your-Factory-Name> "ArmTemplate"' #For using preview that allows you to only stop/ start triggers that are modified, please comment out the above line and uncomment the below line. Make sure the package.json contains the build-preview command. #customCommand: 'run build-preview export $(Build.Repository.LocalPath) /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/GartnerMQ2021/providers/Microsoft.DataFactory/factories/Dev-GartnerMQ2021-DataFactory "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'輸入 YAML 代碼。 以 YAML 檔案作為起點。
儲存並執行。 如果您已使用 YAML,那麼每當 main 分支更新時就會被觸發。 確認這次運行成功,並在管線已發佈的文物中產生
ArmTemplates該文物。
注意
產生的產物本身就包含觸發器的部署前後腳本,所以你不需要手動新增。 不過,部署時仍需參考 停止與啟動觸發器的文件 ,才能執行提供的腳本。
相關內容
了解更多關於 Data Factory 中的持續整合與交付:Azure Data Factory 中的持續整合與交付。