Functions/PlanBranch/Enable-BambooPlanBranch.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
<#
.SYNOPSIS
    Enables a Bamboo plan-branch by its key.
.DESCRIPTION
    It doesn't return any object if it succeeds.
.PARAMETER PlanKey
    Mandatory - Key of the parent plan
.PARAMETER PlanKey
    Mandatory - Name of the branch under the parent plan to be enabled
.EXAMPLE
    Enable-BambooPlan -PlanKey 'PRJ-PLANKEY' -BranchName 'master'
#>

function Enable-BambooPlanBranch {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [ValidatePattern('\w+-\w+')]
        [string]$PlanKey,

        [Parameter(Mandatory)]
        [ValidatePattern('(\w|-)+')]
        [string]$BranchName
    )

    $plan = Get-BambooPlanBranch -PlanKey $PlanKey -BranchName $BranchName
    if ($plan -and ($plan | Get-Member key)) {
        Enable-BambooPlan -PlanKey $plan.key
    } else {
        Write-Error "$PlanKey/$BranchName branch is not found."
    }
}