-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGet-AzDoPipelineRun.ps1
More file actions
109 lines (93 loc) · 3.37 KB
/
Copy pathGet-AzDoPipelineRun.ps1
File metadata and controls
109 lines (93 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
function Get-AzDoPipelineRun {
<#
.SYNOPSIS
Retrieves pipeline run information from Azure DevOps for a specified pipeline within a project.
.DESCRIPTION
The `Get-AzDoPipelineRun` function fetches details about one or more pipeline runs from an Azure DevOps project.
It requires the collection URI, project name, and pipeline ID. Optionally, specific run IDs can be provided
to filter the results. The function uses the `Invoke-AzDoRestMethod` cmdlet to make the REST API call to
Azure DevOps and returns the run details.
.EXAMPLE
$getPipelineRunSplat = @{
CollectionUri = "https://dev.azure.com/YourOrg"
ProjectName = "YourProject"
PipelineId = 123
}
Get-AzDoPipelineRun @getPipelineRunSplat
Retrieves all runs for the specified pipeline in the given project.
.EXAMPLE
$getPipelineRunSplat = @{
CollectionUri = "https://dev.azure.com/YourOrg"
ProjectName = "YourProject"
PipelineId = 123
RunId = 456
}
Get-AzDoPipelineRun @getPipelineRunSplat
Retrieves the details of the specified run (with ID 456) for the given pipeline.
.OUTPUTS
System.Management.Automation.PSCustomObject
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection Uri of the organization
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[string]
$CollectionUri,
# The name of the project containing the pipeline
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]
$ProjectName,
# The ID of the pipeline to retrieve the run for
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[int]$PipelineId,
# The ID of the run to retrieve. If not provided, all runs for the pipeline are returned.
[Parameter(ValueFromPipelineByPropertyName)]
[int[]]$RunId
)
process {
$params = @{
Uri = "$CollectionUri/$ProjectName/_apis/pipelines/$PipelineId/runs"
Version = "6.0"
Method = 'GET'
}
if ($PSCmdlet.ShouldProcess("Pipeline Id: $PipelineId", "Get run")) {
$response = Invoke-AzDoRestMethod @params
$runs = $response.value
if (-not $RunId) {
$runs | ForEach-Object {
[PSCustomObject]@{
PipelineId = $_.pipeline.id
RunId = $_.id
RunName = $_.name
Result = $_.result
State = $_.state
CreatedAt = $_.createdDate
FinishedAt = $_.finishedDate
ProjectName = $ProjectName
CollectionUri = $CollectionUri
URL = $_.url
}
}
return
}
@($runs | Where-Object { $_.id -in $RunId } | ForEach-Object {
[PSCustomObject]@{
PipelineId = $_.pipeline.id
RunId = $_.id
RunName = $_.name
Result = $_.result
State = $_.state
CreatedAt = $_.createdDate
FinishedAt = $_.finishedDate
ProjectName = $ProjectName
CollectionUri = $CollectionUri
URL = $_.url
}
}
)
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
}
}
}