Functions/BuildQueue/Get-BambooQueuedBuild.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<#
.SYNOPSIS
    Gets all or a specific queued build from build activities
.DESCRIPTION
    If PlanKey parameter specified, it returns queued items for
    that single Plan, otherwise it returns all queued item for all
    Plans.
.PARAMETER PlanKey
    Optional - Key for the Bamboo Plan to filter for specific queued items
.EXAMPLE
    Get-BambooQueuedBuild
.EXAMPLE
    Get-BambooQueuedBuild -PlanKey 'PRJ-PLANKEY'
#>

function Get-BambooQueuedBuild {
    [CmdletBinding()]
    param(
        [Parameter()]
        [ValidatePattern('\w+-\w+')]
        [string]$PlanKey
    )

    $resource = 'queue'
    if ($PlanKey) {
        $resource = "queue/$PlanKey"
    }

    Invoke-BambooRestMethod -Resource $resource -Expand 'queuedBuilds' |
    Expand-BambooResource -ResourceName 'queuedBuild' -Root 'queue'
}