To handle renaming and deletion of pipelines effectively, you can utilize pre-deployment and post-deployment scripts. These scripts can manage the state of your ADF pipelines before and after the ARM template deployment. This approach ensures that any deletions or renames in the dev environment are mirrored in the prod environment.
The pre-deployment script can stop all triggers, delete all existing pipelines, and ensure a clean state before deploying the updated ARM template. This will prevent old pipelines from persisting after renames or deletions.
Here's an example of a pre-deployment script:
# Stop all triggers
$triggersADF = Get-AzDataFactoryV2Trigger -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
$triggersADF | ForEach-Object { Stop-AzDataFactoryV2Trigger -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Name $_.name -Force }
# Delete all existing pipelines
$pipelinesADF = Get-AzDataFactoryV2Pipeline -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
$pipelinesADF | ForEach-Object { Remove-AzDataFactoryV2Pipeline -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Name $_.name -Force }
# You can add more deletion commands for datasets, linked services..., if needed
After the pre-deployment script, you can deploy your ARM template. Here’s how you can structure the deployment:
New-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile "$(System.DefaultWorkingDirectory)/<your-arm-template-location>" -Mode Incremental -Name <DeploymentName>
Optionally, you can use a post-deployment script to start the triggers again after the deployment:
# Start all triggers
$triggersADF | ForEach-Object { Start-AzDataFactoryV2Trigger -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Name $_.name -Force }
In your CI/CD pipeline, you can include these scripts as part of the deployment tasks. Here’s a generalized structure:
- Pre-Deployment Task:
- Stop triggers.
- Delete existing pipelines (and other components if necessary).
- ARM Template Deployment Task:
- Deploy the ARM template with the new or updated pipelines.
- Post-Deployment Task (Optional):
- Start triggers.