Functions/New-BMPackage.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

function New-BMPackage
{
    <#
    .SYNOPSIS
    Creates a new package for a release.
 
    .DESCRIPTION
    The `New-BMPackage` creates a new package/version/build of an application. In order to deploy an application, the application must have a release. Then you create packages in that release, and each package is then deployed using the release's pipeline.
 
    .EXAMPLE
    New-BMPackage -Session $session -Release $release
 
    Demonstrates how to create a new package in the `$release` release. BuildMaster detects what application based on the release (since releases are always tied to applications). Verion numbers and package numbers are incremented and handled based on the release settings.
 
    The `$release` parameter can be:
 
    * A release object with an `id` property.
    * A release ID integer.
 
    .EXAMPLE
    New-BMPackage -Session $session -ReleaseName '53' -Application $applicatoin
 
    Demonstrates how to create a new package by using the release's name. Since release names are only unique within an application, you must also specify the application via the `Application` parameter.
 
    .EXAMPLE
    New-BMPackage -Session $session -Release $release -PacakgeName '56.develop' -Variable @{ ProGetPackageName = '17.1.54+developer.deadbee' }
 
    Demonstrates how to create a release with a specific name, `56.develop`, and with a package-level variable, `ProGetPackageName`.
    #>

    [CmdletBinding()]
    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(Mandatory=$true,ParameterSetName='ByReleaseID')]
        [object]
        # The release where the package should be created. Can be:
        #
        # * a release object with an `id` property
        # * the release ID as an integer
        $Release,

        [Parameter(Mandatory=$true,ParameterSetName='ByReleaseNumber')]
        [string]
        # The release number where the package should be created. Release numbers are unique within an application and can be duplicated between applications. If you use this parameter to identify the release, you must also provide a value for the `Application` parameter.
        $ReleaseNumber,

        [Parameter(Mandatory=$true,ParameterSetName='ByReleaseNumber')]
        [object]
        # The application where the release identified by the `ReleaseNumber` parameter can be found. Can be:
        #
        # * An application object with a `Application_Id`, `id`, `Application_Name`, or `name` properties.
        # * The application ID as an integer.
        # * The application name as a string.
        $Application,

        [string]
        # The package number/name. If not provided, BuildMaster generates one based on the release settings.
        $PackageNumber,

        [hashtable]
        # Any package variables to set. Package variables are unique to each package.
        $Variable
    )

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

    $parameters = @{ } 
    
    if( $PSCmdlet.ParameterSetName -eq 'ByReleaseID' )
    {
        $parameters | Add-BMObjectParameter -Name 'release' -Value $Release
    }
    else
    {
        $parameters['releaseNumber'] = $ReleaseNumber
        $parameters | Add-BMObjectParameter -Name 'application' -Value $Application
    }

    if( $PackageNumber )
    {
        $parameters['packageNumber'] = $PackageNumber
    }

    if( $Variable )
    {
        foreach( $key in $Variable.Keys )
        {
            $parameters[('${0}' -f $key)] = $Variable[$key]
        }
    }

    Invoke-BMRestMethod -Session $Session -Name 'releases/packages/create' -Parameter $parameters -Method Post
}