Last active
November 7, 2019 15:23
-
-
Save RandomNoun7/46f34c428a95baeae7f625bc752a8430 to your computer and use it in GitHub Desktop.
Sort build stages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$events = @( | |
[PSCustomObject]@{type = 'phase'; name = 'Build API'; parentID = '1'; id = '2'} | |
[PSCustomObject]@{type = 'task'; name = 'Checkout'; parentID = '3'; id = '5'} | |
[PSCustomObject]@{type = 'task'; name = 'Nuget Tool Installer'; parentID = '3'; id = '6'} | |
[PSCustomObject]@{type = 'task'; name = 'use .NET Core SDK'; parentID = '3'; id = '7'} | |
[PSCustomObject]@{type = 'job'; name = 'Build API'; parentID = '2'; id = '3'} | |
[PSCustomObject]@{type = 'task'; name = 'Initialize Job'; parentID = '3'; id = '4'} | |
[PSCustomObject]@{type = 'Stage'; name = 'Deploy C1'; parentID = ''; id = '8'} | |
[PSCustomObject]@{type = 'Phase'; name = 'Deploy API to SIT'; parentID = '8'; id = '9'} | |
[PSCustomObject]@{type = 'job'; name = 'Deploy API C1'; parentID = '9'; id = '10'} | |
[PSCustomObject]@{type = 'Stage'; name = 'Build Stage'; parentID = ''; id = '1'} | |
[PSCustomObject]@{type = 'task'; name = 'Initialize Job'; parentID = '10'; id = '11'} | |
[PSCustomObject]@{type = 'task'; name = 'Download Artifact'; parentID = '10'; id = '12'} | |
[PSCustomObject]@{type = 'task'; name = 'Download Artifact'; parentID = '10'; id = '13'} | |
[PSCustomObject]@{type = 'task'; name = 'Download Artifact'; parentID = '10'; id = '14'} | |
) | |
function Get-Children { | |
[CmdletBinding()] | |
param ( | |
$collection, | |
[Parameter(ValueFromPipeline=$true)] | |
$currentChild | |
) | |
process { | |
$currentChild | |
$collection | Where-object parentID -eq $currentChild.id | Get-Children -collection $collection | |
} | |
} | |
$events | Where-object parentID -eq '' | Get-Children -collection $events |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment