Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RandomNoun7
Last active November 7, 2019 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RandomNoun7/46f34c428a95baeae7f625bc752a8430 to your computer and use it in GitHub Desktop.
Save RandomNoun7/46f34c428a95baeae7f625bc752a8430 to your computer and use it in GitHub Desktop.
Sort build stages
$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