Skip to content

Commit

Permalink
Support for pipelines, pipeline runs and pipeline logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdejulia authored and mdejulia committed Aug 18, 2020
1 parent 22716b9 commit 6e483f4
Show file tree
Hide file tree
Showing 9 changed files with 1,534 additions and 4 deletions.
10 changes: 6 additions & 4 deletions AzurePipelinesPS/AzurePipelinesPS.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Dejulia489
#
# Generated on: 8/17/2020
# Generated on: 8/18/2020
#

@{
Expand Down Expand Up @@ -90,6 +90,8 @@ FunctionsToExport = 'Add-APDeploymentGroup', 'Add-APGroupMembership', 'Add-APLog
'Get-APNotificationSubscriptionTemplateList', 'Get-APOperation',
'Get-APPackage', 'Get-APPackageList', 'Get-APPermissionReport',
'Get-APPermissionReportList', 'Get-APPersonalAccessTokenList',
'Get-APPipeline', 'Get-APPipelineList', 'Get-APPipelineLog',
'Get-APPipelineLogList', 'Get-APPipelineRun', 'Get-APPipelineRunList',
'Get-APPolicyConfiguration', 'Get-APPolicyConfigurationList',
'Get-APPolicyEvaluation', 'Get-APPolicyEvaluationList',
'Get-APPolicyRevision', 'Get-APPolicyRevisionList',
Expand Down Expand Up @@ -117,9 +119,9 @@ FunctionsToExport = 'Add-APDeploymentGroup', 'Add-APGroupMembership', 'Add-APLog
'New-APEnvironmentApproval', 'New-APFeed', 'New-APGitBranch',
'New-APGroup', 'New-APInstalledExtensionDocument',
'New-APNotificationSubscription', 'New-APPermissionReport',
'New-APPolicyConfiguration', 'New-APProject', 'New-APRelease',
'New-APRepository', 'New-APServiceEndpoint', 'New-APSession',
'New-APTeam', 'Publish-APBuildDefinition',
'New-APPipeline', 'New-APPolicyConfiguration', 'New-APProject',
'New-APRelease', 'New-APRepository', 'New-APServiceEndpoint',
'New-APSession', 'New-APTeam', 'Publish-APBuildDefinition',
'Publish-APReleaseDefinition', 'Register-APPSRepository',
'Remove-APBuild', 'Remove-APBuildDefinition', 'Remove-APDashboard',
'Remove-APDeploymentGroup', 'Remove-APEnvironment', 'Remove-APFeed',
Expand Down
25 changes: 25 additions & 0 deletions AzurePipelinesPS/Private/Get-APApiEndpoint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,31 @@ function Get-APApiEndpoint
'permissions-download'
{
Return '_apis/permissionsreport/{0}/download'

}
'pipelines'
{
Return '_apis/pipelines'
}
'pipelines-pipelineId'
{
Return '_apis/pipelines/{0}'
}
'pipelines-runs'
{
Return '_apis/pipelines/{0}/runs'
}
'pipelines-runId'
{
Return '_apis/pipelines/{0}/runs/{1}'
}
'pipelines-logs'
{
Return '_apis/pipelines/{0}/runs/{1}/logs'
}
'pipelines-logId'
{
Return '_apis/pipelines/{0}/runs/{1}/logs/{2}'
}
'pipelines-configurations'
{
Expand Down
202 changes: 202 additions & 0 deletions AzurePipelinesPS/Public/Get-APPipeline.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
function Get-APPipeline
{
<#
.SYNOPSIS
Returns an Azure Pipeline pipeline.
.DESCRIPTION
Returns an Azure Pipeline pipelines based on a pipeline id.
The pipeline id can be returned with Get-APPipelineList.
.PARAMETER Instance
The Team Services account or TFS server.
.PARAMETER Collection
For Azure DevOps the value for collection should be the name of your orginization.
For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
.PARAMETER Project
Project ID or project name.
.PARAMETER ApiVersion
Version of the api to use.
.PARAMETER PersonalAccessToken
Personal access token used to authenticate that has been converted to a secure string.
It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
.PARAMETER Credential
Specifies a user account that has permission to send the request.
.PARAMETER Proxy
Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
.PARAMETER ProxyCredential
Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
.PARAMETER Session
Azure DevOps PS session, created by New-APSession.
.PARAMETER PipelineId
Id of the pipeline.
.PARAMETER PipelineVersion
The pipeline version.
.INPUTS
None, does not support pipeline.
.OUTPUTS
PSObject, Azure Pipelines pipeline(s)
.EXAMPLE
Returns a Azure Pipeline pipeline for 'myFirstProject' with the id of '7'.
Get-APPipelineList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -PipelineId 7
.LINK
https://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines/get?view=azure-devops-rest-6.0
#>
[CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
Param
(
[Parameter(Mandatory,
ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(Mandatory,
ParameterSetName = 'ByCredential')]
[uri]
$Instance,

[Parameter(Mandatory,
ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(Mandatory,
ParameterSetName = 'ByCredential')]
[string]
$Collection,

[Parameter(Mandatory,
ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(Mandatory,
ParameterSetName = 'ByCredential')]
[string]
$Project,

[Parameter(Mandatory,
ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(Mandatory,
ParameterSetName = 'ByCredential')]
[string]
$ApiVersion,

[Parameter(ParameterSetName = 'ByPersonalAccessToken')]
[Security.SecureString]
$PersonalAccessToken,

[Parameter(ParameterSetName = 'ByCredential')]
[pscredential]
$Credential,

[Parameter(ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(ParameterSetName = 'ByCredential')]
[string]
$Proxy,

[Parameter(ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(ParameterSetName = 'ByCredential')]
[pscredential]
$ProxyCredential,

[Parameter(Mandatory,
ParameterSetName = 'BySession')]
[object]
$Session,

[Parameter()]
[int]
$PipelineId,

[Parameter()]
[int]
$PipelineVersion
)

begin
{
If ($PSCmdlet.ParameterSetName -eq 'BySession')
{
$currentSession = $Session | Get-APSession
If ($currentSession)
{
$Instance = $currentSession.Instance
$Collection = $currentSession.Collection
$Project = $currentSession.Project
$PersonalAccessToken = $currentSession.PersonalAccessToken
$Credential = $currentSession.Credential
$Proxy = $currentSession.Proxy
$ProxyCredential = $currentSession.ProxyCredential
If ($currentSession.Version)
{
$ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
}
else
{
$ApiVersion = $currentSession.ApiVersion
}
}
}
}

process
{
$apiEndpoint = (Get-APApiEndpoint -ApiType 'pipelines-pipelineId') -f $PipelineId
$queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
$setAPUriSplat = @{
Collection = $Collection
Instance = $Instance
Project = $Project
ApiVersion = $ApiVersion
ApiEndpoint = $apiEndpoint
Query = $queryParameters
}
[uri] $uri = Set-APUri @setAPUriSplat
$invokeAPRestMethodSplat = @{
Method = 'GET'
Uri = $uri
Credential = $Credential
PersonalAccessToken = $PersonalAccessToken
Proxy = $Proxy
ProxyCredential = $ProxyCredential
}
$results = Invoke-APRestMethod @invokeAPRestMethodSplat
If ($results.value)
{
return $results.value
}
else
{
return $results
}
}

end
{
}
}
Loading

0 comments on commit 6e483f4

Please sign in to comment.