@@ -7,29 +7,30 @@ function Add-AzDoPipelineBranchControl {
77. EXAMPLE
88 $params = @{
99 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"
1513 }
14+ Add-AzDoPipelineBranchControl @params
1615
17- Set-AzDoBranchPolicyBuildValidation @params
18-
19- This example creates a policy with splatting parameters
20-
16+ Default usage
2117. 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
2727
28+ Add allowed branches and ensure branch protection
2829. OUTPUTS
2930 [PSCustomObject]@{
3031 CollectionUri = $CollectionUri
3132 ProjectName = $ProjectName
32- Id = $_.id
33+ CheckId = $_.id
3334 }
3435. NOTES
3536#>
@@ -61,23 +62,23 @@ function Add-AzDoPipelineBranchControl {
6162 [string []]
6263 $ResourceName ,
6364
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.
6566 [Parameter ()]
6667 [string ]
6768 $AllowUnknownStatusBranches = " false" ,
6869
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
7071 [Parameter ()]
7172 [string ]
7273 $AllowedBranches = " refs/head/main" ,
7374
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.
7576 [Parameter ()]
7677 [string ]
7778 [validateset (" true" , " false" )]
7879 $EnsureProtectionOfBranch = " true" ,
7980
80- # Valid duration of the Build Validation policy. Default is 720 minutes
81+ # Valid duration of the Build Validation policy. Default is 1440 minutes
8182 [Parameter ()]
8283 [int ]
8384 $Timeout = 1440
@@ -89,19 +90,19 @@ function Add-AzDoPipelineBranchControl {
8990
9091 process {
9192
92- $projectId = (Get-AzDoProject - CollectionUri $CollectionUri - ProjectName $ProjectName ).projectId
93-
9493 foreach ($name in $ResourceName ) {
9594
9695 switch ($ResourceType ) {
9796 " environment" {
98- $resourceId = (Get-AzDoEnvironment - CollectionUri $CollectionUri - ProjectName $ProjectName - EnvironmentName $name ).id
97+ $resourceId = (Get-AzDoEnvironment - CollectionUri $CollectionUri - ProjectName $ProjectName - EnvironmentName $name ).EnvironmentId
9998 }
10099 " variablegroup" {
101- $resourceId = (Get-AzDoVariableGroup - CollectionUri $CollectionUri - ProjectName $ProjectName - Name $name ).id
100+ $resourceId = (Get-AzDoVariableGroup - CollectionUri $CollectionUri - ProjectName $ProjectName - VariableGroupName $name ).VariableGroupId
102101 }
103102 " 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
105106 $resourceId = " $ ( $projectId ) .$ ( $repoId ) "
106107 }
107108 }
@@ -134,7 +135,7 @@ function Add-AzDoPipelineBranchControl {
134135 }
135136
136137 $params = @ {
137- uri = " $CollectionUri /$projectId /_apis/pipelines/checks/configurations"
138+ uri = " $CollectionUri /$ProjectName /_apis/pipelines/checks/configurations"
138139 version = " 7.2-preview.1"
139140 Method = " POST"
140141 body = $body
@@ -145,7 +146,7 @@ function Add-AzDoPipelineBranchControl {
145146 [PSCustomObject ]@ {
146147 CollectionUri = $CollectionUri
147148 ProjectName = $ProjectName
148- Id = $_.id
149+ CheckId = $_.id
149150 }
150151 }
151152 } else {
0 commit comments