@@ -7,29 +7,30 @@ function Add-AzDoPipelineBranchControl {
7
7
. EXAMPLE
8
8
$params = @{
9
9
CollectionUri = "https://dev.azure.com/contoso"
10
- PAT = "***"
11
- Name = "Policy 1"
12
- RepoName = "Repo 1"
13
- ProjectName = "Project 1"
14
- Id = 1
10
+ ProjectName = "Project 1"
11
+ ResourceType = "environment"
12
+ ResourceName = "MyEnvironment"
15
13
}
14
+ Add-AzDoPipelineBranchControl @params
16
15
17
- Set-AzDoBranchPolicyBuildValidation @params
18
-
19
- This example creates a policy with splatting parameters
20
-
16
+ Default usage
21
17
. EXAMPLE
22
- $env:SYSTEM_ACCESSTOKEN = '***'
23
- New-AzDoPipeline -CollectionUri "https://dev.azure.com/contoso" -ProjectName "Project 1" -Name "Pipeline 1" -RepoName "Repo 1" -Path "main.yml"
24
- | Set-AzDoBranchPolicyBuildValidation
25
-
26
- This example creates a new Azure Pipeline and sets this pipeline as Build Validation policy on the main branch
18
+ $params = @{
19
+ CollectionUri = "https://dev.azure.com/contoso"
20
+ ProjectName = "Project 1"
21
+ ResourceType = "repository"
22
+ ResourceName = "MyRepo"
23
+ AllowedBranches = "refs/heads/main,refs/heads/develop"
24
+ EnsureProtectionOfBranch = "true"
25
+ }
26
+ Add-AzDoPipelineBranchControl @params
27
27
28
+ Add allowed branches and ensure branch protection
28
29
. OUTPUTS
29
30
[PSCustomObject]@{
30
31
CollectionUri = $CollectionUri
31
32
ProjectName = $ProjectName
32
- Id = $_.id
33
+ CheckId = $_.id
33
34
}
34
35
. NOTES
35
36
#>
@@ -61,23 +62,23 @@ function Add-AzDoPipelineBranchControl {
61
62
[string []]
62
63
$ResourceName ,
63
64
64
- # Valid duration of the Build Validation policy. Default is 720 minutes
65
+ # Allow deployment from branches for which protection status could not be obtained.
65
66
[Parameter ()]
66
67
[string ]
67
68
$AllowUnknownStatusBranches = " false" ,
68
69
69
- # Setup an allow list of branches from which a pipeline must be run to access this resource
70
+ # Setup a comma separated list of branches from which a pipeline must be run to access this resource
70
71
[Parameter ()]
71
72
[string ]
72
73
$AllowedBranches = " refs/head/main" ,
73
74
74
- # Setup a requirement of branch protection policies for the branch from which a pipeline will be run to access this resource
75
+ # Validate the branches being deployed are protected.
75
76
[Parameter ()]
76
77
[string ]
77
78
[validateset (" true" , " false" )]
78
79
$EnsureProtectionOfBranch = " true" ,
79
80
80
- # Valid duration of the Build Validation policy. Default is 720 minutes
81
+ # Valid duration of the Build Validation policy. Default is 1440 minutes
81
82
[Parameter ()]
82
83
[int ]
83
84
$Timeout = 1440
@@ -89,19 +90,19 @@ function Add-AzDoPipelineBranchControl {
89
90
90
91
process {
91
92
92
- $projectId = (Get-AzDoProject - CollectionUri $CollectionUri - ProjectName $ProjectName ).projectId
93
-
94
93
foreach ($name in $ResourceName ) {
95
94
96
95
switch ($ResourceType ) {
97
96
" environment" {
98
- $resourceId = (Get-AzDoEnvironment - CollectionUri $CollectionUri - ProjectName $ProjectName - EnvironmentName $name ).id
97
+ $resourceId = (Get-AzDoEnvironment - CollectionUri $CollectionUri - ProjectName $ProjectName - EnvironmentName $name ).EnvironmentId
99
98
}
100
99
" variablegroup" {
101
- $resourceId = (Get-AzDoVariableGroup - CollectionUri $CollectionUri - ProjectName $ProjectName - Name $name ).id
100
+ $resourceId = (Get-AzDoVariableGroup - CollectionUri $CollectionUri - ProjectName $ProjectName - VariableGroupName $name ).VariableGroupId
102
101
}
103
102
" repository" {
104
- $repoId = (Get-AzDoRepo - CollectionUri $CollectionUri - ProjectName $ProjectName - Name $name ).id
103
+ $projectId = (Get-AzDoProject - CollectionUri $CollectionUri - ProjectName $ProjectName ).projectId
104
+
105
+ $repoId = (Get-AzDoRepo - CollectionUri $CollectionUri - ProjectName $ProjectName - RepoName $name ).RepoId
105
106
$resourceId = " $ ( $projectId ) .$ ( $repoId ) "
106
107
}
107
108
}
@@ -134,7 +135,7 @@ function Add-AzDoPipelineBranchControl {
134
135
}
135
136
136
137
$params = @ {
137
- uri = " $CollectionUri /$projectId /_apis/pipelines/checks/configurations"
138
+ uri = " $CollectionUri /$ProjectName /_apis/pipelines/checks/configurations"
138
139
version = " 7.2-preview.1"
139
140
Method = " POST"
140
141
body = $body
@@ -145,7 +146,7 @@ function Add-AzDoPipelineBranchControl {
145
146
[PSCustomObject ]@ {
146
147
CollectionUri = $CollectionUri
147
148
ProjectName = $ProjectName
148
- Id = $_.id
149
+ CheckId = $_.id
149
150
}
150
151
}
151
152
} else {
0 commit comments