Skip to content

Commit

Permalink
Merge pull request #3 from lholman/add-deploy-environment-support
Browse files Browse the repository at this point in the history
Add 'deploy environment results' support
  • Loading branch information
muratiakos authored Jan 4, 2018
2 parents 08971ec + a7417ea commit f00c41d
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ direct UserName and Password functions to fulfill PSGallery requirements

## 2.0.1 (Mar 9, 2016)
- Fix to set `Content-Type` via Invoke-RestMethod and enforce basic response parsing
## 3.0.0 (Jan 3, 2017)
- Include support for Bamboo Deploy Projects
- Include support for the Environments and Results of Bamboo Deploy Projects
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<#
.SYNOPSIS
Gets all results for the deploy environment
.DESCRIPTION
Gets all results for the deploy environment
.PARAMETER DeployEnvironmentId
Mandatory - Key for the Bamboo Deploy Project to be described
.EXAMPLE
Get-BambooDeployEnvironmentResult -DeployEnvironmentId '65732621'
deployProjectId environmentId buildPlanResultKey deploymentState lifeCycleState startedDate (UTC) finishedDate (UTC)
--------------- ------------- ------------------ --------------- -------------- ----------------- ------------------
65601539 65732621 ABAI-BBAI-9 SUCCESS FINISHED 20171128T0253396970000Z 20171128T0300117170000Z
65601539 65732621 ABAI-BBAI-9 SUCCESS FINISHED 20171128T0201389630000Z 20171128T0236497530000Z
65601539 65732621 ABAI-BBAI-8 SUCCESS FINISHED 20171128T0112255570000Z 20171128T0112575570000Z
65601539 65732621 ABAI-BBAI-8 FAILED FINISHED 20171128T0109390130000Z 20171128T0109478430000Z
65601539 65732621 ABAI-BBAI-8 FAILED FINISHED 20171128T0100426800000Z 20171128T0102268330000Z
#>
function Get-BambooDeployEnvironmentResult {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]$DeployEnvironmentId
)

$ContentType = 'application/json'
Write-Warning "Get-BambooDeployEnvironmentResult: The Bamboo API for 'Deploy Environments' only supports JSON response format. Using content-type: $ContentType"

$resource = "deploy/environment/$DeployEnvironmentId/results"

#Pagination loop variables
$moreItem = $null
$lastIndex = $null
$isSameLoop = $null
$uriParams=@{
'start-index' = 0
}

Do {
$result = $null
$result = Invoke-BambooRestMethod -Resource $resource -ContentType $ContentType -UriParams $uriParams

$result | Expand-BambooResource -ResourceName 'results' -ContentType $ContentType |
Add_ObjectType -TypeName 'PsBamboo.DeployEnvironmentResult'

#Adjust Pagination
$page = $null
$isSameLoop = $True

if ($result -and ($result | Get-Member 'results')) {
$page = $result | Select-Object size, 'start-index', 'max-result'

$uriParams.'start-index' = ([int]$page.'start-index') + ([int]$page.'max-result')
$moreItem = ([int]$page.size) -gt ([int]$uriParams.'start-index')
Write-Verbose "More pages: $moreItem for $page"

$isSameLoop = $lastIndex -eq $page.'start-index'
Write-Verbose "Start-index loop check: '$lastIndex == $($page.'start-index')' => $isSameLoop"

$lastIndex = $page.'start-index'
}

} while ($moreItem -and !$isSameLoop)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>PsBamboo.DeployEnvironmentResult</Name>
<ViewSelectedBy>
<TypeName>PsBamboo.DeployEnvironmentResult</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>deployProjectId</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>environmentId</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>buildPlanResultKey</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>deploymentVersionName</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>deploymentState</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>lifeCycleState</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>startedDate (UTC)</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>finishedDate (UTC)</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<ScriptBlock>($_.key.entityKey.key -split '-')[0]</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>($_.key.entityKey.key -split '-')[1]</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>($_.deploymentVersion.items[0].planResultKey.key)</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>($_.deploymentVersionName)</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>deploymentState</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>lifeCycleState</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>((Get-Date '1/1/1970').AddMilliseconds($_.startedDate).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss"))</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>((Get-Date '1/1/1970').AddMilliseconds($_.finishedDate).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss"))</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<#
.SYNOPSIS
Gets all environments for a Bamboo Deploy Project or describes a single Bamboo Deploy Project environment.
.DESCRIPTION
If -EnvironmentId is specified it describes only that Deploy Project environment.
.PARAMETER DeploymentProjectId
Manatory - Id for the Bamboo Deploy Project to be described
.PARAMETER EnvironmentId
Optional - Id for the Bamboo Deploy Project environment to be described
.EXAMPLE
Get-BambooDeployProjectEnvironment
.EXAMPLE
Get-BambooDeployProjectEnvironment -DeploymentProjectId 65601539 -EnvironmentId 65732617
#>
function Get-BambooDeployProjectEnvironment {
[CmdletBinding()]
param(
[Parameter()]
[ValidatePattern('\w+')]
[string]$DeploymentProjectId
)

$ContentType = 'application/json'
Write-Warning "Get-BambooDeployProjectEnvironment: The Bamboo API for 'Deploy Projects' only supports JSON response format. Using content-type: $ContentType"

$resource = "deploy/project/$DeploymentProjectId"

Invoke-BambooRestMethod -Resource $resource -ContentType $ContentType | Expand-BambooResource -ResourceName 'environments' |
Add_ObjectType -TypeName 'PsBamboo.DeployEnvironment'

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>PsBamboo.DeployEnvironment</Name>
<ViewSelectedBy>
<TypeName>PsBamboo.DeployEnvironment</TypeName>
</ViewSelectedBy>
<TableControl>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>deploymentProjectId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>description</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>position</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
11 changes: 10 additions & 1 deletion Functions/Expand-BambooResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ function Expand-BambooResource {
[string]$PluralResourceName="$($ResourceName)s",

[Parameter()]
[string]$Root=$PluralResourceName
[string]$Root=$PluralResourceName,

[Parameter(Mandatory=$False)]
[string]$ContentType='application/xml'

)

if ($null -eq $Response) { return }

if ($ContentType -eq 'application/json') {
if ($Response.size -eq 0) {
return
}
}

if ($Response | Get-Member $Root) {
if ($Response.$Root.$PluralResourceName | Get-Member $ResourceName) {
$response.$Root.$PluralResourceName.$ResourceName
Expand Down
4 changes: 3 additions & 1 deletion PsBamboo.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
RootModule = 'PsBamboo.psm1'

# Version number of this module.
ModuleVersion = '2.2.1.0'
ModuleVersion = '3.0.0.0'

# ID used to uniquely identify this module
GUID = '85aaff1a-c696-43ad-be1a-53d16477d01d'
Expand Down Expand Up @@ -74,7 +74,9 @@ FunctionsToExport = @(
'Expand-BambooResource'
'Get-BambooArtifact'
'Get-BambooCurrentUser'
'Get-BambooDeployEnvironmentResult'
'Get-BambooDeployProject'
'Get-BambooDeployProjectEnvironment'
'Get-BambooInfo'
'Get-BambooPlan'
'Get-BambooPlanBranch'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PsBamboo is a PowerShell module that provides a wrapper for [Bamboo][bamboo]

The module handles both authenticated and anonymous methods, it supports paged
reading and manipulation of the following [Bamboo][bamboo] resources:
`Project`, `Plan`, `PlanBranch`, `Build`, `Artifact`, `Server`, `CurrentUser`
`Project`, `Plan`, `PlanBranch`, `Build`, `Artifact`, `Server`, `CurrentUser`,`DeployProject`

In addition to several already implemented functions, it also provides
generic Cmdlets to access any not yet covered [Bamboo REST API][bambooapi]
Expand Down
2 changes: 2 additions & 0 deletions Tests/BambooModule/expected_commands.csv
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Get-BambooArtifact
Get-BambooBuild
Get-BambooBuildLog
Get-BambooCurrentUser
Get-BambooDeployEnvironmentResult
Get-BambooDeployProject
Get-BambooDeployProjectEnvironment
Get-BambooInfo
Get-BambooPlan
Get-BambooPlanBranch
Expand Down

0 comments on commit f00c41d

Please sign in to comment.