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

function New-BMPipeline
{
    <#
    .SYNOPSIS
    Creates a new pipeline in BuildMaster.
 
    .DESCRIPTION
    The `New-BMPipeline` function creates a new pipeline in BuildMaster and retuns an object representing the new pipeline. In order to deploy an application, you must create a release for that application. Each release gets assigned a pipeline, which are the set of steps to do when releasing and deploying. Pipelines can belong to a specific application or shared between applications.
 
    The pipeline is created with no stages. The following settings are enabled:
 
    * Enforce pipeline stage order for deployments
 
    The following settings are disabled:
 
    * Cancel earlier (lower-sequenced) releases that are still active and have not yet been deployed.
    * Create a new release by incrementing the final part after a release has been deployed.
    * Mark the release and package as deployed once it reaches the final stage.
 
    This function uses [BuildMaster's native API](http://inedo.com/support/documentation/buildmaster/reference/api/native).
 
    .EXAMPLE
    New-BMPipeline -Session $session -Name 'Powershell Module'
 
    Demonstrates how to create a new pipeline that is not used by any applications. In this example a pipeline named `PowerShell Module` will be created.
 
    .EXAMPLE
    New-BMPipeline -Session $session -Name 'PowerShell Module' -Application $app
 
    Demonstrates how to create a new pipeline and assign it to a specific application. In this example, the pipeline will be called `PowerShell Module` and it will be assigned to the `$app` application.
    #>

    [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)]
        [string]
        # The name of the pipeline.
        $Name,

        [object]
        # The application to assign the pipeline to. Can be:
        #
        # * An application object with `Application_Id`, `id`, `Application_Name`, or `name` properties.
        # * An application ID (must be an integer)
        # * An applicatoin name (must be a string)
        $Application,

        [string]
        # The background color BuildMaster should use when displaying the pipeline's name in the UI. Should be a CSS hexadecimal color, e.g. `#ffffff`
        $Color,

        [string[]]
        # Stage configuration for the pipeline. Should be an array of `<Inedo.BuildMaster.Pipelines.PipelineStage>` XML elements.
        $Stage
    )

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

    $pipelineParams = @{
                        'Pipeline_Name' = $Name;
                        'Pipeline_Configuration' = @"
<Inedo.BuildMaster.Pipelines.Pipeline Assembly="BuildMaster">
  <Properties Name="Standard" Description="" EnforceStageSequence="True">
     <Stages>
        $( $Stage -join [Environment]::NewLine )
     </Stages>
     <PostDeploymentOptions>
        <Inedo.BuildMaster.Pipelines.PipelinePostDeploymentOptions Assembly="BuildMaster">
           <Properties CreateRelease="False" CancelReleases="False" DeployRelease="False" />
        </Inedo.BuildMaster.Pipelines.PipelinePostDeploymentOptions>
     </PostDeploymentOptions>
  </Properties>
</Inedo.BuildMaster.Pipelines.Pipeline>
"@
;
                        'Active_Indicator' = $true;
                   }
    if( $Application )
    {
        $pipelineParams | Add-BMObjectParameter -Name 'application' -Value $Application -ForNativeApi
    }

    if( $Color )
    {
        $pipelineParams['Pipeline_Color'] = $Color
    }

    $pipelineId = Invoke-BMNativeApiMethod -Session $session -Name 'Pipelines_CreatePipeline' -Parameter $pipelineParams -Method Post
    if( $pipelineId )
    {
        Invoke-BMNativeApiMethod -Session $session -Name 'Pipelines_GetPipeline' -Parameter @{ 'Pipeline_Id' = $pipelineId } -Method Post
    }
}