Skip to content

Commit 150aee2

Browse files
authored
Merge branch 'main' into fix/Add-AzDoPipelineBranchControl
2 parents 2eb7bb1 + e4a9c2d commit 150aee2

12 files changed

Lines changed: 325 additions & 162 deletions

AzureDevOpsPowerShell/Private/Invoke-AzDoRestMethod.ps1

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ function Invoke-AzDoRestMethod {
3131
[string]
3232
$Method,
3333

34-
[Parameter()]
35-
[string]
36-
$Pat,
37-
3834
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
3935
[PSCustomObject[]]
4036
$Body
@@ -47,7 +43,7 @@ function Invoke-AzDoRestMethod {
4743
Write-Debug "method: $Method"
4844
Write-Debug "body: $($body | ConvertTo-Json -Depth 10)"
4945

50-
if (-not($Pat) -and $script:header) {
46+
if ($script:header.Authorization -match "Bearer") {
5147
$params = @{
5248
Uri = "https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=6.0"
5349
Method = 'GET'
@@ -62,13 +58,13 @@ function Invoke-AzDoRestMethod {
6258
}
6359
} catch {
6460
Write-Verbose "Refreshing authentication header"
65-
Clear-AzDoAuthHeader
61+
$script:header = $null
6662
}
6763
}
6864

6965
if (-not($script:header)) {
7066
try {
71-
New-AzDoAuthHeader -PAT $Pat -ErrorAction Stop
67+
New-AzDoAuthHeader -ErrorAction Stop
7268
} catch {
7369
throw $_
7470
}

AzureDevOpsPowerShell/Public/Api/Pipelines/Pipelines/New-AzDoPipeline.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ function New-AzDoPipeline {
6565
RepoName = $RepoName
6666
}
6767

68-
Write-Debug "Calling Get-AzDoRepo with"
69-
$RepoId = (Get-AzDoRepo @getAzDoRepoSplat).RepoId
68+
Write-Debug "Calling Get-AzDoRepo with $($getAzDoRepoSplat| ConvertTo-Json -Depth 10)"
69+
$RepoId = (Get-AzDoRepo @getAzDoRepoSplat -ErrorAction Stop).RepoId
7070

7171
$body = @{
7272
name = $PipelineName

AzureDevOpsPowerShell/Public/Api/ServiceEndpoints/Endpoints/New-AzDoServiceConnection.ps1

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,28 @@ function New-AzDoServiceConnection {
6464
[string]
6565
$Description = '',
6666

67-
# Scope level (Subscription or ManagementGroup).
67+
# Parameter help description
6868
[Parameter(ValueFromPipelineByPropertyName)]
69+
[Switch]
70+
$Force,
71+
72+
# Create the service connection as draft (useful when creating a WorkloadIdentityFederation based service connection).
73+
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'WorkloadIdentityFederation')]
74+
[switch]
75+
$AsDraft,
76+
77+
# Scope level (Subscription or ManagementGroup).
78+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'ServiceprincipalSecret')]
79+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'ServiceprincipalCertificate')]
6980
[ValidateSet('Subscription', 'ManagementGroup')]
7081
[string]
71-
$ScopeLevel = 'Subscription',
82+
$ScopeLevel,
83+
84+
# AuthenticationType (spnSecret or spnCertificate).
85+
[Parameter(ValueFromPipelineByPropertyName)]
86+
[ValidateSet('spnSecret', 'spnCertificate', 'WorkloadIdentityFederation')]
87+
[string]
88+
$AuthenticationType = 'WorkloadIdentityFederation',
7289

7390
# ID of the subscriptionn.
7491
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'Subscription')]
@@ -91,21 +108,19 @@ function New-AzDoServiceConnection {
91108
$ManagementGroupName,
92109

93110
# ID of the tenant.
94-
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
111+
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'WorkloadIdentityFederation')]
112+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'ServiceprincipalSecret')]
113+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'ServiceprincipalCertificate')]
95114
[string]
96115
$TenantId,
97116

98117
# Client ID of the app registration.
99-
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
118+
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'WorkloadIdentityFederation')]
119+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'ServiceprincipalSecret')]
120+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'ServiceprincipalCertificate')]
100121
[string]
101122
$ServiceprincipalId,
102123

103-
# AuthenticationType (spnSecret or spnCertificate).
104-
[Parameter(ValueFromPipelineByPropertyName)]
105-
[ValidateSet('spnSecret', 'spnCertificate', 'WorkloadIdentityFederation')]
106-
[string]
107-
$AuthenticationType = 'WorkloadIdentityFederation',
108-
109124
# App secret of the app registation.
110125
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'ServiceprincipalSecret')]
111126
[string]
@@ -119,17 +134,7 @@ function New-AzDoServiceConnection {
119134
# Name of the certificate
120135
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'ServiceprincipalCertificate')]
121136
[string]
122-
$CertName,
123-
124-
# Create the service connection as draft (useful when creating a WorkloadIdentityFederation based service connection).
125-
[Parameter(ValueFromPipelineByPropertyName)]
126-
[switch]
127-
$AsDraft,
128-
129-
# Parameter help description
130-
[Parameter(ValueFromPipelineByPropertyName)]
131-
[Switch]
132-
$Force
137+
$CertName
133138
)
134139

135140
begin {

AzureDevOpsPowerShell/Public/Helpers/Clear-AzDoAuthHeader.ps1

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function Set-AzDoPAT {
2+
<#
3+
.SYNOPSIS
4+
This script sets the header variable with a PAT.
5+
.DESCRIPTION
6+
This script sets the header variable with a PAT.
7+
.NOTES
8+
This function can be used to use a PAT for authentication instead of an Azure PowerShell access token.
9+
.EXAMPLE
10+
Set-AzDoPAT -Pat '***'
11+
12+
This example sets the header variable used for authentication with a PAT.
13+
#>
14+
[CmdletBinding(SupportsShouldProcess)]
15+
param (
16+
# PAT used for authentication
17+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
18+
[string]
19+
$Pat
20+
)
21+
22+
process {
23+
if ($PSCmdlet.ShouldProcess()) {
24+
New-AzDoAuthHeader -Pat $Pat
25+
} else {
26+
Write-Verbose "Calling New-AzDoAuthHeader with pat"
27+
}
28+
}
29+
}

docs/en-US/Add-AzDoPipelineBranchControl.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
243243
## OUTPUTS
244244
245245
### [PSCustomObject]@{
246-
### CollectionUri = $CollectionUri
247-
### ProjectName = $ProjectName
248-
### Id = $_.id
246+
### CollectionUri = $CollectionUri
247+
### ProjectName = $ProjectName
248+
### Id = $_.id
249249
### }
250250
## NOTES
251251

docs/en-US/Clear-AzDoAuthHeader.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ schema: 2.0.0
1313
## SYNTAX
1414

1515
```
16-
Clear-AzDoAuthHeader [-ProgressAction <ActionPreference>] [<CommonParameters>]
16+
Clear-AzDoAuthHeader [<CommonParameters>]
1717
```
1818

1919
## DESCRIPTION
@@ -30,21 +30,6 @@ PS C:\> {{ Add example code here }}
3030

3131
## PARAMETERS
3232

33-
### -ProgressAction
34-
{{ Fill ProgressAction Description }}
35-
36-
```yaml
37-
Type: ActionPreference
38-
Parameter Sets: (All)
39-
Aliases: proga
40-
41-
Required: False
42-
Position: Named
43-
Default value: None
44-
Accept pipeline input: False
45-
Accept wildcard characters: False
46-
```
47-
4833
### CommonParameters
4934
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
5035

docs/en-US/Get-AzDoPipeline.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
---
2+
external help file: AzureDevOpsPowerShell-help.xml
3+
Module Name: AzureDevOpsPowerShell
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Get-AzDoPipeline
9+
10+
## SYNOPSIS
11+
Creates a Build Validation policy on a branch
12+
13+
## SYNTAX
14+
15+
```
16+
Get-AzDoPipeline [-CollectionUri] <String> [-ProjectName] <String> [[-PipelineName] <String[]>]
17+
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
Creates a Build Validation policy on a branch
22+
23+
## EXAMPLES
24+
25+
### EXAMPLE 1
26+
```
27+
$params = @{
28+
CollectionUri = "https://dev.azure.com/contoso"
29+
PAT = "***"
30+
Name = "Policy 1"
31+
RepoName = "Repo 1"
32+
ProjectName = "Project 1"
33+
Id = 1
34+
}
35+
Set-AzDoBranchPolicyBuildValidation @params
36+
```
37+
38+
This example creates a policy with splatting parameters
39+
40+
### EXAMPLE 2
41+
```
42+
$env:SYSTEM_ACCESSTOKEN = '***'
43+
New-AzDoPipeline -CollectionUri "https://dev.azure.com/contoso" -ProjectName "Project 1" -Name "Pipeline 1" -RepoName "Repo 1" -Path "main.yml"
44+
| Set-AzDoBranchPolicyBuildValidation
45+
```
46+
47+
This example creates a new Azure Pipeline and sets this pipeline as Build Validation policy on the main branch
48+
49+
## PARAMETERS
50+
51+
### -CollectionUri
52+
Collection Uri of the organization
53+
54+
```yaml
55+
Type: String
56+
Parameter Sets: (All)
57+
Aliases:
58+
59+
Required: True
60+
Position: 1
61+
Default value: None
62+
Accept pipeline input: True (ByPropertyName, ByValue)
63+
Accept wildcard characters: False
64+
```
65+
66+
### -ProjectName
67+
Project where the pipeline will be created.
68+
69+
```yaml
70+
Type: String
71+
Parameter Sets: (All)
72+
Aliases:
73+
74+
Required: True
75+
Position: 2
76+
Default value: None
77+
Accept pipeline input: True (ByPropertyName, ByValue)
78+
Accept wildcard characters: False
79+
```
80+
81+
### -PipelineName
82+
Name of the Build Validation policy.
83+
Default is the name of the Build Definition
84+
85+
```yaml
86+
Type: String[]
87+
Parameter Sets: (All)
88+
Aliases:
89+
90+
Required: False
91+
Position: 3
92+
Default value: None
93+
Accept pipeline input: True (ByPropertyName, ByValue)
94+
Accept wildcard characters: False
95+
```
96+
97+
### -WhatIf
98+
Shows what would happen if the cmdlet runs.
99+
The cmdlet is not run.
100+
101+
```yaml
102+
Type: SwitchParameter
103+
Parameter Sets: (All)
104+
Aliases: wi
105+
106+
Required: False
107+
Position: Named
108+
Default value: None
109+
Accept pipeline input: False
110+
Accept wildcard characters: False
111+
```
112+
113+
### -Confirm
114+
Prompts you for confirmation before running the cmdlet.
115+
116+
```yaml
117+
Type: SwitchParameter
118+
Parameter Sets: (All)
119+
Aliases: cf
120+
121+
Required: False
122+
Position: Named
123+
Default value: None
124+
Accept pipeline input: False
125+
Accept wildcard characters: False
126+
```
127+
128+
### -ProgressAction
129+
{{ Fill ProgressAction Description }}
130+
131+
```yaml
132+
Type: ActionPreference
133+
Parameter Sets: (All)
134+
Aliases: proga
135+
136+
Required: False
137+
Position: Named
138+
Default value: None
139+
Accept pipeline input: False
140+
Accept wildcard characters: False
141+
```
142+
143+
### CommonParameters
144+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
145+
146+
## INPUTS
147+
148+
## OUTPUTS
149+
150+
### [PSCustomObject]@{
151+
### CollectionUri = $CollectionUri
152+
### ProjectName = $ProjectName
153+
### RepoName = $RepoName
154+
### Id = $result.id
155+
### Url = $result.url
156+
### }
157+
## NOTES
158+
159+
## RELATED LINKS

0 commit comments

Comments
 (0)