Functions/Get-BMDeployment.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

function Get-BMDeployment
{
    <#
    .SYNOPSIS
    Gets a deployment from BuildMaster.
 
    .DESCRIPTION
    The `Get-BMDeployment` function gets deployments in BuildMaster. It uses the [Release and Package Deployment API](http://inedo.com/support/documentation/buildmaster/reference/api/release-and-package).
 
    To get a specific deployment, pass a deploymentID.
 
    To get all the deployments for a specific package, pass a package object to the `Package` parameter (a package object must have a `packageId` or `packageNumber` property).
 
    To get all the deployments for a specific release, pass a release object to the `Release` parameter (a release object must have a `releaseId` or `releaseName` property).
 
    To get all the deployments for a specific application, pass an application object to the `Application` parameter (an application object must have an `applicationId` or `applicationName` property).
 
    .EXAMPLE
    Get-BMDeployment -Session $session
 
    Demonstrates how to get all deployments from the instance of BuildMaster.
 
    .EXAMPLE
    Get-BMDeployment -Session $session -ID $deployment
 
    Demonstrates how to get a specific deployment by passing a deployment object to the `Deployment` parameter. The `Get-BMDeployment` function looks for an `id` property on the object.
 
    .EXAMPLE
    Get-BMDeployment -Session $session -Package $package
 
    Demonstrates how to get all deployments for a package by passing a package object to the `Package` parameter. The `Get-BMDeployment` function looks for an `id` or `number` property on the object.
 
    .EXAMPLE
    Get-BMDeployment -Session $session -Release $release
 
    Demonstrates how to get all deployments for a release by passing a release object to the `Release` parameter. The `Get-BMDeployment` function looks for an `id` or `name` property on the object.
 
    .EXAMPLE
    Get-BMDeployment -Session $session -Application $app
 
    Demonstrates how to get all deployments for an application by passing an application object to the `Application` parameter. The `Get-BMDeployment` function looks for an `id` or `name` property on the object.
 
    .EXAMPLE
    Get-BMDeployment -Session $session -Application 34
 
    Demonstrates how to get all deployments for an application by passing its ID to the `Application` parameter.
    #>

    [CmdletBinding(DefaultParameterSetName='AllDeployments')]
    param(
        [Parameter(Mandatory)]
        [object]
        # A session object that contains the settings to use to connect to BuildMaster. Use `New-BMSession` to create session objects.
        $Session,

        [Parameter(Mandatory,ParameterSetName='ByDeployment')]
        [int]
        # The deployment to get. You can pass:
        #
        # * A deployment ID (as an integer)
        $ID,

        [Parameter(Mandatory,ParameterSetName='ByPackage')]
        [object]
        # The package whose deployments to get. You can pass:
        #
        # * A package ID as an integer
        # * A package name/number as a string.
        $Package,

        [Parameter(Mandatory,ParameterSetName='ByRelease')]
        [object]
        # The release whose deployments to get. You can pass:
        #
        # * The release ID as an integer.
        # * The release name as a string.
        $Release,

        [Parameter(Mandatory,ParameterSetName='ByApplication')]
        [object]
        # The application whose deployments to get. You can pass:
        #
        # * The application ID as an integer.
        # * The application name as a string.
        $Application
    )

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

        $parameter = @{ }
        if( $PSCmdlet.ParameterSetName -eq 'ByDeployment' )
        {
            $parameter | Add-BMObjectParameter -Name 'deployment' -Value $ID
        }
        elseif( $PSCmdlet.ParameterSetName -eq 'ByPackage' )
        {
            if( $Package -is [string] )
            {
                $parameter['packageNumber'] = $Package
            }
            else
            {
                $parameter | Add-BMObjectParameter -Name 'package' -Value $Package
            }
        }
        elseif( $PSCmdlet.ParameterSetName -eq 'ByRelease' )
        {
            $parameter | Add-BMObjectParameter -Name 'release' -Value $Release
        }
        elseif( $PSCmdlet.ParameterSetName -eq 'ByApplication' )
        {
            $parameter | Add-BMObjectParameter -Name 'application' -Value $Application
        }

        Invoke-BMRestMethod -Session $Session -Name 'releases/packages/deployments' -Parameter $parameter -Method Post
    }
}