Skip to content

Commit 3a285c1

Browse files
committed
feat: Add function Get-PipelineRun
Add function Get-PipelineRun that gets all or specific runs from the specified pipeline
1 parent 4100a2b commit 3a285c1

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function Get-PipelineRun {
2+
<#
3+
.SYNOPSIS
4+
Retrieves pipeline run information from Azure DevOps for a specified pipeline within a project.
5+
.DESCRIPTION
6+
The `Get-PipelineRun` function fetches details about one or more pipeline runs from an Azure DevOps project.
7+
It requires the collection URI, project name, and pipeline ID. Optionally, specific run IDs can be provided
8+
to filter the results. The function uses the `Invoke-AzDoRestMethod` cmdlet to make the REST API call to
9+
Azure DevOps and returns the run details.
10+
.EXAMPLE
11+
Get-PipelineRun -CollectionUri "https://dev.azure.com/YourOrg" -ProjectName "YourProject" -PipelineId 123
12+
Retrieves all runs for the specified pipeline in the given project.
13+
.EXAMPLE
14+
Get-PipelineRun -CollectionUri "https://dev.azure.com/YourOrg" -ProjectName "YourProject" -PipelineId 123 -RunId 456
15+
Retrieves the details of the specified run (with ID 456) for the given pipeline.
16+
.OUTPUTS
17+
Returns an array of pipeline run objects. If specific run IDs are provided, only the matching runs are returned.
18+
.NOTES
19+
#>
20+
[CmdletBinding(SupportsShouldProcess)]
21+
param (
22+
# Collection Uri of the organization
23+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
24+
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
25+
[string]
26+
$CollectionUri,
27+
28+
# The name of the project containing the pipeline
29+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
30+
[string]
31+
$ProjectName,
32+
33+
# The ID of the pipeline to retrieve the run for
34+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
35+
[int]$PipelineId,
36+
37+
# The ID of the run to retrieve. If not provided, all runs for the pipeline are returned.
38+
[Parameter(ValueFromPipelineByPropertyName)]
39+
[int[]]$RunId
40+
)
41+
42+
process {
43+
$params = @{
44+
Uri = "$CollectionUri/$ProjectName/_apis/pipelines/$PipelineId/runs"
45+
Version = "6.0"
46+
Method = 'GET'
47+
}
48+
49+
if ($PSCmdlet.ShouldProcess("Pipeline Id: $PipelineId", "Get run")) {
50+
$response = Invoke-AzDoRestMethod @params
51+
$runs = $response.value
52+
53+
if (-not $RunId) {
54+
return $runs
55+
}
56+
57+
$runs | Where-Object { $_.id -in $RunId }
58+
} else {
59+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
60+
}
61+
}
62+
}
63+

0 commit comments

Comments
 (0)