-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from lholman/add-deploy-environment-support
Add 'deploy environment results' support
- Loading branch information
Showing
9 changed files
with
219 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Functions/DeployEnvironmentResult/Get-BambooDeployEnvironmentResult.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
69 changes: 69 additions & 0 deletions
69
Functions/DeployEnvironmentResult/PsBamboo.DeployEnvironmentResult.format.ps1xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
31 changes: 31 additions & 0 deletions
31
Functions/DeployProjectEnvironment/Get-BambooDeployProjectEnvironment.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
Functions/DeployProjectEnvironment/PsBamboo.DeployEnvironment.format.ps1xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters