title | description | ms.subservice | author | ms.author | ms.reviewer | ms.topic | ms.date | ms.custom |
---|---|---|---|---|---|---|---|---|
Continuous integration and delivery pre- and post-deployment scripts |
Learn how to use a pre- and post-deployment script with continuous integration and delivery in Azure Data Factory from this sample. |
ci-cd |
nabhishek |
abnarain |
jburchel |
conceptual |
09/26/2024 |
devx-track-azurepowershell |
[!INCLUDEappliesto-adf-xxx-md]
The following sample demonstrates how to use a pre- and post-deployment script with continuous integration and delivery in Azure Data Factory.
Install the latest Azure PowerShell modules by following instructions in How to install and configure Azure PowerShell.
Warning
Make sure to use PowerShell Core in ADO task to run the script
The sample scripts to stop/ start triggers and update global parameters during release process (CICD) are located in the Azure Data Factory Official GitHub page.
Note
Use the PrePostDeploymentScript.Ver2.ps1 if you would like to turn off/ on only the triggers that have been modified instead of turning all triggers off/ on during CI/CD.
The following sample script can be used to stop triggers before deployment and restart them afterward. The script also includes code to delete resources that have been removed. Save the script in an Azure DevOps git repository and reference it via an Azure PowerShell task the latest Azure PowerShell version.
When running a predeployment script, you need to specify a variation of the following parameters in the Script Arguments field.
-armTemplate "$(System.DefaultWorkingDirectory)/<your-arm-template-location>" -ResourceGroupName <your-resource-group-name> -DataFactoryName <your-data-factory-name> -predeployment $true -deleteDeployment $false
When running a postdeployment script, you need to specify a variation of the following parameters in the Script Arguments field.
-armTemplate "$(System.DefaultWorkingDirectory)/<your-arm-template-location>" -ResourceGroupName <your-resource-group-name> -DataFactoryName <your-data-factory-name> -predeployment $false -deleteDeployment $true
Note
The -deleteDeployment
flag is used to specify the deletion of the ADF deployment entry from the deployment history in ARM.
:::image type="content" source="media/continuous-integration-delivery/continuous-integration-image11.png" alt-text="Azure PowerShell task":::
The following YAML code executes a script that can be used to stop triggers before deployment and restart them afterward. The script also includes code to delete resources that have been removed. If you're following the steps outlined in New CI/CD Flow, this script is exported as part of artifact created via the npm publish package.
- 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: ../
- 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: ../