Skip to content

Commit f982a64

Browse files
authored
Merge pull request #51 from WeAreInSpark/fix/Add-AzDoPipelineBranchControl
fix: Fixing ResourceId fetching
2 parents e4a9c2d + 150aee2 commit f982a64

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

AzureDevOpsPowerShell/Public/Api/ApprovalsAndChecks/CheckConfigurations/Add-AzDoPipelineBranchControl.ps1

+27-26
Original file line numberDiff line numberDiff line change
@@ -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 {

AzureDevOpsPowerShell/Public/Api/DistributedTask/VariableGroups/Get-AzDoVariableGroup.ps1

+7-7
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ function Get-AzDoVariableGroup {
7878
if ($result) {
7979
$result | ForEach-Object {
8080
[PSCustomObject]@{
81-
CollectionURI = $CollectionUri
82-
ProjectName = $ProjectName
83-
Name = $_.name
84-
Id = $_.id
85-
Variables = $_.variables
86-
CreatedOn = $_.createdOn
87-
IsShared = $_.isShared
81+
CollectionURI = $CollectionUri
82+
ProjectName = $ProjectName
83+
Name = $_.name
84+
VariableGroupId = $_.id
85+
Variables = $_.variables
86+
CreatedOn = $_.createdOn
87+
IsShared = $_.isShared
8888
}
8989
}
9090
}

AzureDevOpsPowerShell/Public/Api/Environments/Environments/Get-AzDoEnvironment.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function Get-AzDoEnvironment {
7878
[PSCustomObject]@{
7979
CollectionUri = $CollectionUri
8080
ProjectName = $ProjectName
81-
Id = $_.id
81+
EnvironmentId = $_.id
8282
EnvironmentName = $_.name
8383
}
8484
}

0 commit comments

Comments
 (0)