Skip to content

Commit e6c77c0

Browse files
authored
Add custom ObjectName field to all exported objects - Fix #73 (#76)
* Add custom ObjectName field to all exported objects - Fix #73
1 parent d829ed9 commit e6c77c0

File tree

10 files changed

+126
-113
lines changed

10 files changed

+126
-113
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
tests/out*
22
coverage.xml
3-
myenv.ps1
3+
myenv.ps1
4+
.vscode/

src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Core.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,14 @@ function Export-AzDevOpsPipelineYaml {
228228

229229
Write-Verbose "Getting YAML definition for pipeline $PipelineId"
230230
$yaml = "ObjectType: Azure.DevOps.Pipelines.PipelineYaml`n"
231-
$yaml += Get-AzDevOpsPipelineYaml -Project $Project -PipelineId $PipelineId
231+
$yaml += "ObjectName: '$($script:connection.Organization).$Project.$PipelineName.Yaml'`n"
232+
$yamlTemp = Get-AzDevOpsPipelineYaml -Project $Project -PipelineId $PipelineId
232233
# Export the YAML definition to a file if it is not empty
233-
if ($yaml -eq "ObjectType: Azure.DevOps.Pipelines.PipelineYaml`n" -or $null -eq $yaml) {
234+
if ($null -eq $yamlTemp) {
234235
Write-Warning "YAML definition for pipeline $PipelineId is empty"
235236
return $null
236-
}
237+
} else {
238+
$yaml += $yamlTemp}
237239
Write-Verbose "Exporting YAML definition to $OutputPath\$PipelineName.yaml"
238240
$yaml | Out-File "$OutputPath\$PipelineName.yaml"
239241
}
@@ -277,6 +279,7 @@ function Export-AzDevOpsPipelines {
277279
foreach ($pipeline in $pipelines) {
278280
# Add ObjectType Azure.DevOps.Pipeline to the pipeline object
279281
$pipeline | Add-Member -MemberType NoteProperty -Name ObjectType -Value "Azure.DevOps.Pipeline"
282+
$pipeline | Add-Member -MemberType NoteProperty -Name ObjectName -Value ("{0}.{1}.{2}" -f $script:connection.Organization,$Project,$pipeline.name)
280283
# Get the project ID from the pipeline object web.href property
281284
$ProjectId = $pipeline._links.web.href.Split('/')[4]
282285

src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Environments.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ function Export-AzDevOpsEnvironmentChecks {
156156
$environment = $_
157157
# Add a ObjectType indicator for Azure.DevOps.Pipelines.Environment
158158
$environment | Add-Member -MemberType NoteProperty -Name ObjectType -Value 'Azure.DevOps.Pipelines.Environment'
159+
$environment | Add-Member -MemberType NoteProperty -Name ObjectName -Value ("{0}.{1}.{2}" -f $script:connection.Organization,$Project,$environment.name)
159160
$checks = @(Get-AzDevOpsEnvironmentChecks -Project $Project -Environment $environment.id)
160161
$environment | Add-Member -MemberType NoteProperty -Name checks -Value $checks
161162
Write-Verbose "Exporting environment $($environment.name) to JSON"

src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Releases.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ Function Export-AzDevOpsReleaseDefinitions {
159159
$definitionPath = Join-Path -Path $OutputPath -ChildPath "$definitionName.ado.rd.json"
160160
# Add an ObjectType of Azure.DevOps.Pipelines.Releases.Definition to the response
161161
$response | Add-Member -MemberType NoteProperty -Name 'ObjectType' -Value 'Azure.DevOps.Pipelines.Releases.Definition'
162+
$response | Add-Member -MemberType NoteProperty -Name 'ObjectName' -Value ("{0}.{1}.{2}" -f $script:connection.Organization,$Project,$definitionName)
162163
# Get the project ID from the url in the response
163164
$projectId = $response.url.Split('/')[4]
164165
# Get the folder from the path in the response

src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Settings.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function Export-AzDevOpsPipelinesSettings {
7272
Write-Verbose "Getting pipelines settings from Azure DevOps"
7373
$pipelinesSettings = Get-AzDevOpsPipelinesSettings -Project $Project
7474
$pipelinesSettings | Add-Member -MemberType NoteProperty -Name ObjectType -Value 'Azure.DevOps.Pipelines.Settings'
75+
$pipelinesSettings | Add-Member -MemberType NoteProperty -Name ObjectName -Value ("{0}.{1}.PipelineSettings" -f $script:connection.Organization,$Project)
7576
$pipelinesSettings | Add-Member -MemberType NoteProperty -Name Name -Value $Project
7677
$pipelinesSettings | ConvertTo-Json -Depth 10 | Out-File (Join-Path -Path $OutputPath -ChildPath "$Project.ado.pls.json")
7778
}

src/PSRule.Rules.AzureDevOps/Functions/DevOps.Repos.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ function Export-AzDevOpsReposAndBranchPolicies {
370370
$repo = $_
371371
# Add ObjectType Azure.DevOps.Repo to repo object
372372
$repo | Add-Member -MemberType NoteProperty -Name ObjectType -Value "Azure.DevOps.Repo"
373+
# Add ObjectName to repo object
374+
$repo | Add-Member -MemberType NoteProperty -Name ObjectName -Value ("{0}.{1}.{2}" -f $Organization,$Project,$repo.name)
373375
Write-Verbose "Getting branch policy for repo $($repo.name)"
374376
If($repo.defaultBranch) {
375377
$branchPolicy = Get-AzDevOpsBranchPolicy -Project $Project -Repository $repo.id -Branch $repo.defaultBranch

src/PSRule.Rules.AzureDevOps/Functions/DevOps.ServiceConnections.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ function Export-AzDevOpsServiceConnections {
130130
$serviceConnection = $_
131131
# Set JSON ObjectType field to Azure.DevOps.ServiceConnection
132132
$serviceConnection | Add-Member -MemberType NoteProperty -Name ObjectType -Value 'Azure.DevOps.ServiceConnection'
133+
# Set JSON ObjectName field to organiztion.project.service connection name
134+
$serviceConnection | Add-Member -MemberType NoteProperty -Name ObjectName -Value "$Organization.$Project.$($serviceConnection.name)"
133135
# Get checks for service connection
134136
$serviceConnectionChecks = @(Get-AzDevOpsServiceConnectionChecks -Project $Project -ServiceConnectionId $serviceConnection.id)
135137
$serviceConnection | Add-Member -MemberType NoteProperty -Name Checks -Value $serviceConnectionChecks

src/PSRule.Rules.AzureDevOps/Functions/DevOps.Tasks.VariableGroups.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Function Export-AzDevOpsVariableGroups {
8181
$variableGroups | ForEach-Object {
8282
$variableGroup = $_
8383
$variableGroup | Add-Member -MemberType NoteProperty -Name 'ObjectType' -Value 'Azure.DevOps.Tasks.VariableGroup'
84+
$variableGroup | Add-Member -MemberType NoteProperty -Name 'ObjectName' -Value "$Organization.$Project.$($variableGroup.name)"
8485
$variableGroupName = $variableGroup.name
8586
$variableGroupPath = Join-Path -Path $OutputPath -ChildPath "$variableGroupName.ado.vg.json"
8687
Write-Verbose "Exporting variable group $variableGroupName as file $variableGroupName.ado.vg.json"

src/PSRule.Rules.AzureDevOps/rules/Config.Rule.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
binding:
99
useQualifiedName: true
1010
targetName:
11+
- ObjectName
1112
- name
1213
- displayName
1314
- id

0 commit comments

Comments
 (0)