Skip to content

Commit 311479f

Browse files
authored
Merge pull request #103563 from djpmsft/docUpdates
updating CI/CD powershell script
2 parents a41a78c + 20e133b commit 311479f

File tree

1 file changed

+134
-3
lines changed

1 file changed

+134
-3
lines changed

articles/data-factory/continuous-integration-deployment.md

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,133 @@ param
213213
[parameter(Mandatory = $false)] [Bool] $deleteDeployment=$false
214214
)
215215

216+
function getPipelineDependencies {
217+
param([System.Object] $activity)
218+
if ($activity.Pipeline) {
219+
return @($activity.Pipeline.ReferenceName)
220+
} elseif ($activity.Activities) {
221+
$result = @()
222+
return $activity.Activities | ForEach-Object{ $result += getPipelineDependencies -activity $_ }
223+
} elseif ($activity.ifFalseActivities -or $activity.ifTrueActivities) {
224+
$result = @()
225+
$activity.ifFalseActivities | Where-Object {$_ -ne $null} | ForEach-Object{ $result += getPipelineDependencies -activity $_ }
226+
$activity.ifTrueActivities | Where-Object {$_ -ne $null} | ForEach-Object{ $result += getPipelineDependencies -activity $_ }
227+
} elseif ($activity.defaultActivities) {
228+
$result = @()
229+
$activity.defaultActivities | ForEach-Object{ $result += getPipelineDependencies -activity $_ }
230+
if ($activity.cases) {
231+
$activity.cases | ForEach-Object{ $_.activities } | ForEach-Object{$result += getPipelineDependencies -activity $_ }
232+
}
233+
return $result
234+
}
235+
}
236+
237+
function pipelineSortUtil {
238+
param([Microsoft.Azure.Commands.DataFactoryV2.Models.PSPipeline]$pipeline,
239+
[Hashtable] $pipelineNameResourceDict,
240+
[Hashtable] $visited,
241+
[System.Collections.Stack] $sortedList)
242+
if ($visited[$pipeline.Name] -eq $true) {
243+
return;
244+
}
245+
$visited[$pipeline.Name] = $true;
246+
$pipeline.Activities | ForEach-Object{ getPipelineDependencies -activity $_ -pipelineNameResourceDict $pipelineNameResourceDict} | ForEach-Object{
247+
pipelineSortUtil -pipeline $pipelineNameResourceDict[$_] -pipelineNameResourceDict $pipelineNameResourceDict -visited $visited -sortedList $sortedList
248+
}
249+
$sortedList.Push($pipeline)
250+
251+
}
252+
253+
function Get-SortedPipelines {
254+
param(
255+
[string] $DataFactoryName,
256+
[string] $ResourceGroupName
257+
)
258+
$pipelines = Get-AzDataFactoryV2Pipeline -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
259+
$ppDict = @{}
260+
$visited = @{}
261+
$stack = new-object System.Collections.Stack
262+
$pipelines | ForEach-Object{ $ppDict[$_.Name] = $_ }
263+
$pipelines | ForEach-Object{ pipelineSortUtil -pipeline $_ -pipelineNameResourceDict $ppDict -visited $visited -sortedList $stack }
264+
$sortedList = new-object Collections.Generic.List[Microsoft.Azure.Commands.DataFactoryV2.Models.PSPipeline]
265+
266+
while ($stack.Count -gt 0) {
267+
$sortedList.Add($stack.Pop())
268+
}
269+
$sortedList
270+
}
271+
272+
function triggerSortUtil {
273+
param([Microsoft.Azure.Commands.DataFactoryV2.Models.PSTrigger]$trigger,
274+
[Hashtable] $triggerNameResourceDict,
275+
[Hashtable] $visited,
276+
[System.Collections.Stack] $sortedList)
277+
if ($visited[$trigger.Name] -eq $true) {
278+
return;
279+
}
280+
$visited[$trigger.Name] = $true;
281+
$trigger.Properties.DependsOn | Where-Object {$_ -and $_.ReferenceTrigger} | ForEach-Object{
282+
triggerSortUtil -trigger $triggerNameResourceDict[$_.ReferenceTrigger.ReferenceName] -triggerNameResourceDict $triggerNameResourceDict -visited $visited -sortedList $sortedList
283+
}
284+
$sortedList.Push($trigger)
285+
}
286+
287+
function Get-SortedTriggers {
288+
param(
289+
[string] $DataFactoryName,
290+
[string] $ResourceGroupName
291+
)
292+
$triggers = Get-AzDataFactoryV2Trigger -DataFactoryName miliutesteu04 -ResourceGroupName miliu
293+
$triggerDict = @{}
294+
$visited = @{}
295+
$stack = new-object System.Collections.Stack
296+
$triggers | ForEach-Object{ $triggerDict[$_.Name] = $_ }
297+
$triggers | ForEach-Object{ triggerSortUtil -trigger $_ -triggerNameResourceDict $triggerDict -visited $visited -sortedList $stack }
298+
$sortedList = new-object Collections.Generic.List[Microsoft.Azure.Commands.DataFactoryV2.Models.PSTrigger]
299+
300+
while ($stack.Count -gt 0) {
301+
$sortedList.Add($stack.Pop())
302+
}
303+
$sortedList
304+
}
305+
306+
function Get-SortedLinkedServices {
307+
param(
308+
[string] $DataFactoryName,
309+
[string] $ResourceGroupName
310+
)
311+
$linkedServices = Get-AzDataFactoryV2LinkedService -DataFactoryName miliutesteu04 -ResourceGroupName miliu
312+
$LinkedServiceHasDependencies = @('HDInsightLinkedService', 'HDInsightOnDemandLinkedService', 'AzureBatchLinkedService')
313+
$Akv = 'AzureKeyVaultLinkedService'
314+
$HighOrderList = New-Object Collections.Generic.List[Microsoft.Azure.Commands.DataFactoryV2.Models.PSLinkedService]
315+
$RegularList = New-Object Collections.Generic.List[Microsoft.Azure.Commands.DataFactoryV2.Models.PSLinkedService]
316+
$AkvList = New-Object Collections.Generic.List[Microsoft.Azure.Commands.DataFactoryV2.Models.PSLinkedService]
317+
318+
$linkedServices | ForEach-Object {
319+
if ($_.Properties.GetType().Name -in $LinkedServiceHasDependencies) {
320+
$HighOrderList.Add($_)
321+
}
322+
elseif ($_.Properties.GetType().Name -eq $Akv) {
323+
$AkvList.Add($_)
324+
}
325+
else {
326+
$RegularList.Add($_)
327+
}
328+
}
329+
330+
$SortedList = New-Object Collections.Generic.List[Microsoft.Azure.Commands.DataFactoryV2.Models.PSLinkedService]($HighOrderList.Count + $RegularList.Count + $AkvList.Count)
331+
$SortedList.AddRange($HighOrderList)
332+
$SortedList.AddRange($RegularList)
333+
$SortedList.AddRange($AkvList)
334+
$SortedList
335+
}
336+
216337
$templateJson = Get-Content $armTemplate | ConvertFrom-Json
217338
$resources = $templateJson.resources
218339

219340
#Triggers
220341
Write-Host "Getting triggers"
221-
$triggersADF = Get-AzDataFactoryV2Trigger -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
342+
$triggersADF = Get-SortedTriggers -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
222343
$triggersTemplate = $resources | Where-Object { $_.type -eq "Microsoft.DataFactory/factories/triggers" }
223344
$triggerNames = $triggersTemplate | ForEach-Object {$_.name.Substring(37, $_.name.Length-40)}
224345
$activeTriggerNames = $triggersTemplate | Where-Object { $_.properties.runtimeState -eq "Started" -and ($_.properties.pipelines.Count -gt 0 -or $_.properties.pipeline.pipelineReference -ne $null)} | ForEach-Object {$_.name.Substring(37, $_.name.Length-40)}
@@ -237,10 +358,15 @@ else {
237358
#Deleted resources
238359
#pipelines
239360
Write-Host "Getting pipelines"
240-
$pipelinesADF = Get-AzDataFactoryV2Pipeline -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
361+
$pipelinesADF = Get-SortedPipelines -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
241362
$pipelinesTemplate = $resources | Where-Object { $_.type -eq "Microsoft.DataFactory/factories/pipelines" }
242363
$pipelinesNames = $pipelinesTemplate | ForEach-Object {$_.name.Substring(37, $_.name.Length-40)}
243364
$deletedpipelines = $pipelinesADF | Where-Object { $pipelinesNames -notcontains $_.Name }
365+
#dataflows
366+
$dataflowsADF = Get-AzDataFactoryV2DataFlow -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
367+
$dataflowsTemplate = $resources | Where-Object { $_.type -eq "Microsoft.DataFactory/factories/dataflows" }
368+
$dataflowsNames = $dataflowsTemplate | ForEach-Object {$_.name.Substring(37, $_.name.Length-40) }
369+
$deleteddataflow = $dataflowsADF | Where-Object { $dataflowsNames -notcontains $_.Name }
244370
#datasets
245371
Write-Host "Getting datasets"
246372
$datasetsADF = Get-AzDataFactoryV2Dataset -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
@@ -249,7 +375,7 @@ else {
249375
$deleteddataset = $datasetsADF | Where-Object { $datasetsNames -notcontains $_.Name }
250376
#linkedservices
251377
Write-Host "Getting linked services"
252-
$linkedservicesADF = Get-AzDataFactoryV2LinkedService -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
378+
$linkedservicesADF = Get-SortedLinkedServices -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
253379
$linkedservicesTemplate = $resources | Where-Object { $_.type -eq "Microsoft.DataFactory/factories/linkedservices" }
254380
$linkedservicesNames = $linkedservicesTemplate | ForEach-Object {$_.name.Substring(37, $_.name.Length-40)}
255381
$deletedlinkedservices = $linkedservicesADF | Where-Object { $linkedservicesNames -notcontains $_.Name }
@@ -275,6 +401,11 @@ else {
275401
Write-Host "Deleting pipeline " $_.Name
276402
Remove-AzDataFactoryV2Pipeline -Name $_.Name -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Force
277403
}
404+
Write-Host "Deleting dataflows"
405+
$deleteddataflow | ForEach-Object {
406+
Write-Host "Deleting dataflow " $_.Name
407+
Remove-AzDataFactoryV2DataFlow -Name $_.Name -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Force
408+
}
278409
Write-Host "Deleting datasets"
279410
$deleteddataset | ForEach-Object {
280411
Write-Host "Deleting dataset " $_.Name

0 commit comments

Comments
 (0)