Skip to content

Commit f01d975

Browse files
authored
Merge pull request #62 from WeAreInSpark/feature-get-run
feat: Add function Get-PipelineRun
2 parents e707aaf + 36edb2f commit f01d975

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
13+
Retrieves all runs for the specified pipeline in the given project.
14+
.EXAMPLE
15+
Get-PipelineRun -CollectionUri "https://dev.azure.com/YourOrg" -ProjectName "YourProject" -PipelineId 123 -RunId 456
16+
17+
Retrieves the details of the specified run (with ID 456) for the given pipeline.
18+
.OUTPUTS
19+
Returns an array of pipeline run objects. If specific run IDs are provided, only the matching runs are returned.
20+
.NOTES
21+
#>
22+
[CmdletBinding(SupportsShouldProcess)]
23+
param (
24+
# Collection Uri of the organization
25+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
26+
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
27+
[string]
28+
$CollectionUri,
29+
30+
# The name of the project containing the pipeline
31+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
32+
[string]
33+
$ProjectName,
34+
35+
# The ID of the pipeline to retrieve the run for
36+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
37+
[int]$PipelineId,
38+
39+
# The ID of the run to retrieve. If not provided, all runs for the pipeline are returned.
40+
[Parameter(ValueFromPipelineByPropertyName)]
41+
[int[]]$RunId
42+
)
43+
44+
process {
45+
$params = @{
46+
Uri = "$CollectionUri/$ProjectName/_apis/pipelines/$PipelineId/runs"
47+
Version = "6.0"
48+
Method = 'GET'
49+
}
50+
51+
if ($PSCmdlet.ShouldProcess("Pipeline Id: $PipelineId", "Get run")) {
52+
$response = Invoke-AzDoRestMethod @params
53+
$runs = $response.value
54+
55+
if (-not $RunId) {
56+
return $runs
57+
}
58+
59+
$runs | Where-Object { $_.id -in $RunId }
60+
} else {
61+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
62+
}
63+
}
64+
}
65+

0 commit comments

Comments
 (0)