Functions/Get-BMPipeline.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

function Get-BMPipeline
{
    <#
    .SYNOPSIS
    Gets pipelines.
 
    .DESCRIPTION
    The `Get-BMPipeline` function gets pipelines. By default, it returns all pipelines. To get a specific pipeline, pass its name to the `Name` parameter or its ID to the `ID` parameter. The `Name` parameter supports wildcards. To get a specific application's pipelines, pass the application's ID to the `ApplicationID` parameter.
 
    This function uses the `Pipelines_GetPipelines` and `Pipelines_GetPipeline` native API methods.
 
    .EXAMPLE
    Get-BMPipeline -Session $session
 
    Demonstrates how to get all the pipelines.
 
    .EXAMPLE
    Get-BMPipeline -Session $session -Name 'BuildMaster Automation'
 
    Demonstrates how to get pipelines by name. If there are multiple pipelines with the same name, they will all be returned.
 
    .EXAMPLE
    Get-BMPipeline -Session $session -Name '*Automation'
 
    Demonstrates that you can use wildcards in the `Name` parameter's value to search for pipelines.
     
    .EXAMPLE
    Get-BMPipeline -Session $session -ID 34
 
    Demonstrates how to get a specific pipeline by its ID.
     
    .EXAMPLE
    Get-BMPipeline -Session $session -ApplicationID 39
 
    Demonstrates how to get a specific application's pipelines.
     
    .EXAMPLE
    Get-BMPipeline -Session $session -ApplicationID 39 -Name 'Pipeline 2'
 
    Demonstrates how to get an application's pipeline by its name.
    #>

    [CmdletBinding(DefaultParameterSetName='Searching')]
    param(
        [Parameter(Mandatory=$true)]
        [object]
        # An object that represents the instance of BuildMaster to connect to. Use the `New-BMSession` function to creates a session object.
        $Session,

        [Parameter(ParameterSetName='Searching')]
        [string]
        # The name of the pipeline to get. Supports wildcards.
        $Name,

        [Parameter(ParameterSetName='Searching')]
        [int]
        # The ID of the application whose pipelines to get. The default is to return all pipelines.
        $ApplicationID,

        [Parameter(Mandatory=$true,ParameterSetName='SpecificPipeline')]
        [int]
        # The ID of the pipeline to get.
        $ID
    )

    Set-StrictMode -Version 'Latest'
    Use-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState

    $parameter = @{ }
    $methodName = 'Pipelines_GetPipelines'
    if( $PSCmdlet.ParameterSetName -eq 'SpecificPipeline' )
    {
        $methodName = 'Pipelines_GetPipeline'
        $parameter['Pipeline_Id'] = $ID
    }
    else
    {
        if( $ApplicationID )
        {
            $parameter['Application_Id'] = $ApplicationID
        }
    }

    $optionalParams = @{ }
    if( $parameter.Count )
    {
        $optionalParams['Parameter'] = $parameter
        $optionalParams['Method'] = 'Post'
    }

    Invoke-BMNativeApiMethod -Session $session -Name $methodName @optionalParams |
        Where-Object {
            if( $Name )
            {
                return ($_.Pipeline_Name -like $Name)
            }
            
            return $true
        }
}