stages: - stage: 'DeploytoDev' variables: - group: services displayName: 'Deploy to Dev' jobs: - deployment: environment: Dev strategy: runOnce: deploy: steps: - task: AzurePowerShell@5 displayName: 'Uninstall AzureRm' inputs: azureSubscription: 'xxxxxxx' ScriptType: 'inlineScript' errorActionPreference: 'continue' inline: 'Uninstall-AzureRm' azurePowerShellVersion: 'LatestVersion' - task: DownloadBuildArtifacts@1 displayName: 'Down Build Artifacts' inputs: buildType: 'specific' project: 'xxxxxxxxxx' pipeline: 'xxxx' buildVersionToDownload: 'latest' downloadType: 'specific' downloadPath: '$(System.ArtifactsDirectory)' - task: AzureKeyVault@2 displayName: 'Fetch Storage Key from Key Vault' inputs: connectedServiceName: 'xxxxxx' KeyVaultName: 'xxxxx' SecretsFilter: 'xxxxx' runAsPreJob: false - task: AzurePowerShell@5 displayName: 'Stop specified ADF triggers from file' inputs: azureSubscription: 'xxxxx' ScriptType: 'InlineScript' azurePowerShellVersion: 'LatestVersion' Inline: | # Path to the trigger list file relative to the repository root $triggersFile = "$(System.ArtifactsDirectory)\drop\TriggersList-Dev.txt" $resourceGroupName = "xxxx" $dataFactoryName = "xxxx" # Check if the trigger file exists if (Test-Path $triggersFile) { # Read the trigger names from the file, one per line $triggersToStop = Get-Content -Path $triggersFile # Loop through each trigger name and start it foreach ($triggerName in $triggersToStop) { # Check for empty lines to avoid errors if (-not [string]::IsNullOrWhiteSpace($triggerName)) { Write-Host "Attempting to stop trigger: $triggerName" # Use stop-AzDataFactoryV2Trigger to start the trigger Stop-AzDataFactoryV2Trigger ` -ResourceGroupName $resourceGroupName ` -DataFactoryName $dataFactoryName ` -Name $triggerName ` -Force } } } else { Write-Error "Trigger file not found at: $triggersFile" exit 1 } - task: PublishADFTask@1 displayName: 'Deploy ADF to Instance' inputs: azureSubscription: 'xxxx' ResourceGroupName: 'xxxx' DataFactoryName: 'xxxx' DataFactoryCodePath: '$(System.ArtifactsDirectory)/drop' Location: 'xxxx' CreateNewInstance: false StageCode: 'Dev' PublishMethod: 'AzResource' IncrementalDeployment: false StopStartTriggers: false DeleteNotInSource: false - powershell: | Write-Host "Waiting for 1 minute before next task..." Start-Sleep -Seconds 60 displayName: 'Add a 1 minute delay' - task: AzurePowerShell@5 displayName: 'Start specified ADF triggers from file' inputs: azureSubscription: 'xxxxx' ScriptType: 'InlineScript' azurePowerShellVersion: 'LatestVersion' Inline: | # Path to the trigger list file relative to the repository root $triggersFile = "$(System.ArtifactsDirectory)\drop\TriggersList-Dev.txt" $resourceGroupName = "xxx" $dataFactoryName = "xxx" # Check if the trigger file exists if (Test-Path $triggersFile) { # Read the trigger names from the file, one per line $triggersToStart = Get-Content -Path $triggersFile # Loop through each trigger name and start it foreach ($triggerName in $triggersToStart) { # Check for empty lines to avoid errors if (-not [string]::IsNullOrWhiteSpace($triggerName)) { Write-Host "Processing to start trigger: $triggerName" # Get full trigger object to check its type $trigger = Get-AzDataFactoryV2Trigger ` -ResourceGroupName $resourceGroupName ` -DataFactoryName $dataFactoryName ` -Name $triggerName if ($trigger.TriggerType -eq "BlobEventsTrigger" -or $trigger.TriggerType -eq "CustomEventsTrigger") { Write-Host "Subscribing $($trigger.Name) to events..." $status = Add-AzDataFactoryV2TriggerSubscription ` -ResourceGroupName $resourceGroupName ` -DataFactoryName $dataFactoryName ` -Name $trigger.Name while ($status.Status -ne "Enabled") { Write-Host "Waiting for subscription to enable for trigger: $($trigger.Name)" Start-Sleep -Seconds 15 $status = Get-AzDataFactoryV2TriggerSubscriptionStatus ` -ResourceGroupName $resourceGroupName ` -DataFactoryName $dataFactoryName ` -Name $trigger.Name } } Write-Host "Starting trigger: $triggerName" Start-AzDataFactoryV2Trigger ` -ResourceGroupName $resourceGroupName ` -DataFactoryName $dataFactoryName ` -Name $triggerName ` -Force } } } else { Write-Error "Trigger file not found at: $triggersFile" exit 1 }