Functions/Publish-BMReleasePackage.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

function Publish-BMReleasePackage
{
    <#
    .SYNOPSIS
    Deploys a release package in BuildMaster.
 
    .DESCRIPTION
    The `Publish-BMReleasePackage` deploys a release package in BuildMaster. The package is deployed using the pipeline assigned to the release the package is part of. This function uses BuildMaster's [Release and Package Deployment API](http://inedo.com/support/documentation/buildmaster/reference/api/release-and-package).
 
    Pass the package to deploy to the `Package` parameter. This can be a package object or a package ID (as an integer).
 
    To deploy a package, it must be part of a release that has a pipeline. That pipeline must have at least one stage and that stage must have a plan. If none of these conditions are met, you'll get no object back with no errors written.
 
    .EXAMPLE
    Publish-BMReleasePackage -Session $session -Package $package
 
    Demonstrates how to deploy a package by passing a package object to the `Package` parameter. This object must have an `id` or `pipeline_id` property.
     
    .EXAMPLE
    Publish-BMReleasePackage -Session $session -Package 383
 
    Demonstrates how to deploy a package by passing its ID to the `Package` parameter.
 
    .EXAMPLE
    Publish-BMReleasePackage -Session $session -Package $package -Stage $stage
 
    Demonstrates how to deploy a package to a specific stage of the release pipeline. By default, a package will deploy to the first stage of the assigned pipeline.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [object]
        # An object representing the BuildMaster instance to connect to. Use the `New-BMSession` function to create a session object.
        $Session,

        [Parameter(Mandatory=$true)]
        [object]
        # The package to deploy. Can be:
        #
        # * A package object which has an `id` property.
        # * The package's ID, as an integer.
        $Package,
        
        [string]
        # The name of the pipeline stage where the package will be deployed.
        $Stage,

        [Switch]
        # Instructs BuildMaster to run the deploy even if the deploy to previous stages failed.
        $Force
    )

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

    $parameters = @{} | Add-BMObjectParameter -Name 'package' -Value $Package -PassThru
    
    if( $Stage )
    {
        $parameters['toStage'] = $Stage
    }

    if( $Force )
    {
        $parameters['force'] = 'true'
    }
    
    Invoke-BMRestMethod -Session $Session -Name 'releases/packages/deploy' -Parameter $parameters -Method Post
}