Examples/ProjectAndPlan.examples.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
param(
    [Parameter()]
    [string]$Server = 'http://localhost:8085',

    [Parameter(Mandatory=$true)]
    [pscredential]$Credential
)

# Use local module for the examples
Remove-Module PsBamboo -ErrorAction SilentlyContinue
$localModule = Join-Path (Split-Path $PSScriptRoot -Parent) "PsBamboo.psm1"
Import-Module $localModule

#region Server login and Info
    Write-Host "Set Bamboo Server and Login Credentials" -ForegroundColor Cyan
    Set-BambooServer -Url $Server
    Get-BambooServer

    Set-BambooAuthentication -Credential $Credential

    Get-BambooInfo
    Get-BambooCurrentUser | Format-List

#endregion

#region Project Demo

    Read-Host "Get all Projects - Press ENTER"
    $AllProjects = Get-BambooProject
    $AllProjects | Out-Host

    Read-Host "Detail a specific Project - Press ENTER"
    $First = $AllProjects | Select -First 1 -ExpandProperty key
    $FirstProject = Get-BambooProject -ProjectKey $First
    $FirstProject | Format-List

#endregion

#region Plan Demo

    Read-Host "List Plans - Press ENTER"
    $Plans = Get-BambooPlan
    $Plans | Format-Table Key,Name

    Read-Host "Detail a specific Plan - Press ENTER"
    $FirstPlan = $Plans | Select -First 1 -ExpandProperty key
    Get-BambooPlan -PlanKey $FirstPlan | Out-Host

    Read-Host "Disable Plan and show details - Press ENTER"
    Disable-BambooPlan -PlanKey $FirstPlan
    Get-BambooPlan -PlanKey $FirstPlan | Out-Host

    Read-Host "Re-enable Plan and show details - Press ENTER"
    Enable-BambooPlan -PlanKey $FirstPlan
    Get-BambooPlan -PlanKey $FirstPlan | Out-Host

    $NewPlanKey = "$($FirstPlan)$(Get-Random -Maximum 1000)"
    Read-Host "Copy (Clone) $FirstPlan to $NewPlanKey Plan - Press Enter"
    $NewPlan = Copy-BambooPlan -PlanKey $FirstPlan -NewPlanKey $NewPlanKey
    $NewPlan | Out-Host

#endregion

#region PlanBranch demo

    Write-Host "Manipulate PlanBranches" -ForegroundColor Cyan

    Read-Host "Add a new PlanBranch - Press ENTER"
    $BranchName='pester'
    $VcsBranch='feature/pester'
    $NewBranchPlan = Add-BambooPlanBranch -PlanKey $NewPlanKey -BranchName $BranchName -VcsBranch $VcsBranch
    $NewBranchPlan | Out-Host

    Read-Host "Enable PlanBranch - Press ENTER"
    Enable-BambooPlanBranch -PlanKey $NewPlanKey -BranchName $BranchName
    Get-BambooPlanBranch -PlanKey $NewPlanKey -BranchName $BranchName | Out-Host

    Read-Host "Disable PlanBranch - Press ENTER"
    Disable-BambooPlanBranch -PlanKey $NewPlanKey -BranchName $BranchName
    Get-BambooPlanBranch -PlanKey $NewPlanKey -BranchName $BranchName | Out-Host

#endregion