-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinventory-clusters.yml
More file actions
141 lines (128 loc) · 6.56 KB
/
Copy pathinventory-clusters.yml
File metadata and controls
141 lines (128 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# AZLOCAL-PIPELINE-ID: inventory-clusters
# Step.01 - Inventory Azure Local Clusters
# This pipeline queries all Azure Local clusters and exports inventory with UpdateRing tag status
#
# OUTPUT COLUMNS:
# ClusterName, ResourceGroup, SubscriptionId, SubscriptionName,
# UpdateRing, HasUpdateRingTag, UpdateStartWindow, UpdateExclusions,
# UpdateSideloaded, UpdateVersionInProgress, ResourceId
#
# - UpdateSideloaded (operator-set): True/False/1/0 - sideloaded-payload gate
# - UpdateVersionInProgress (module-managed; do not edit): staged update name
# See main module README, section "Sideloaded Payload Workflow".
# BEGIN-AZLOCAL-CUSTOMIZE:schedule-triggers
# Content between BEGIN/END markers is preserved by Update-AzLocalPipelineExample
# across module upgrades. Edit the cron below or add more `- cron:` entries
# to suit your maintenance windows.
trigger: none
schedules:
# Run weekly on Monday at 6:00 AM UTC
- cron: '0 6 * * 1'
displayName: 'Weekly Inventory'
branches:
include:
- main
always: true
# END-AZLOCAL-CUSTOMIZE:schedule-triggers
parameters:
- name: subscriptionFilter
displayName: 'Subscription ID Filter (leave empty for all subscriptions)'
type: string
default: ''
- name: moduleVersion
displayName: 'Pin AzLocal.UpdateManagement version (empty = latest from PSGallery). See Automation-Pipeline-Examples/README.md section 5 "Optional configuration".'
type: string
default: ''
variables:
# Module version this YAML was generated against. The install step compares this to
# the version actually installed and to the latest on PSGallery, and emits a warning
# log if the YAML appears stale - prompting you to refresh via
# Copy-AzLocalPipelineExample -Update. See Automation-Pipeline-Examples/README.md section 5.
- name: GENERATED_AGAINST_MODULE_VERSION
value: '0.8.76'
# Resolution order for the module version pin (leave all unset to install the latest,
# which is the default "fix-forward" behaviour): queue-time parameter > pipeline variable
# 'REQUIRED_MODULE_VERSION' overridden at queue time > empty (latest).
- name: REQUIRED_MODULE_VERSION
value: '${{ parameters.moduleVersion }}'
pool:
vmImage: 'windows-latest'
stages:
- stage: Inventory
displayName: 'Inventory Azure Local Clusters'
jobs:
- job: InventoryClusters
displayName: 'Run Cluster Inventory'
steps:
- checkout: self
displayName: 'Checkout Repository'
- task: AzureCLI@2
displayName: 'Install Resource Graph Extension'
inputs:
azureSubscription: 'AzureLocal-ServiceConnection' # Update with your service connection name
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az extension add --name resource-graph --yes
- task: PowerShell@2
displayName: 'Install AzLocal.UpdateManagement from PSGallery'
# v0.8.5 thin-YAML: drift detection + banner + step outputs are all
# produced by Add-AzLocalPipelineVersionBanner (Public cmdlet).
env:
REQUIRED_MODULE_VERSION: $(REQUIRED_MODULE_VERSION)
GENERATED_AGAINST_MODULE_VERSION: $(GENERATED_AGAINST_MODULE_VERSION)
inputs:
targetType: 'inline'
pwsh: true
script: |
$ErrorActionPreference = 'Stop'
$installArgs = @{ Name = 'AzLocal.UpdateManagement'; Scope = 'CurrentUser'; Force = $true; AllowClobber = $true }
if ($env:REQUIRED_MODULE_VERSION) {
$installArgs.RequiredVersion = $env:REQUIRED_MODULE_VERSION
Write-Host "REQUIRED_MODULE_VERSION is set - pinning install to v$($env:REQUIRED_MODULE_VERSION)."
} else {
Write-Host "REQUIRED_MODULE_VERSION is empty - installing the latest version from PSGallery (default fix-forward behaviour)."
}
Install-Module @installArgs
Import-Module AzLocal.UpdateManagement -Force
$banner = Add-AzLocalPipelineVersionBanner `
-GeneratedAgainstVersion $env:GENERATED_AGAINST_MODULE_VERSION `
-PinnedVersion $env:REQUIRED_MODULE_VERSION `
-PassThru
# Forward to ADO job-scoped variables so the inventory step (below)
# can stamp the installed module version into README_Instructions.txt.
Write-Host "##vso[task.setvariable variable=installedModuleVersion;isOutput=false]$($banner.InstalledVersion)"
- task: AzureCLI@2
displayName: 'Run Cluster Inventory'
inputs:
azureSubscription: 'AzureLocal-ServiceConnection' # Update with your service connection name
scriptType: 'pscore'
scriptLocation: 'inlineScript'
# v0.8.5 thin-YAML: the inline run block (inventory query, dual
# CSV/JSON export, canonical CSV copy, README_Instructions.txt,
# per-pipeline summary, separate 'Generate Summary' task) has
# been condensed into the Public cmdlet
# Invoke-AzLocalClusterInventory. The cmdlet writes the four
# artifacts to -OutputDirectory, emits the markdown summary via
# ##vso[task.uploadsummary], and sets the four step outputs.
inlineScript: |
$ErrorActionPreference = 'Stop'
Import-Module AzLocal.UpdateManagement -Force
Invoke-AzLocalClusterInventory `
-OutputDirectory "$(Build.ArtifactStagingDirectory)" `
-SubscriptionFilter "${{ parameters.subscriptionFilter }}" `
-InstalledModuleVersion "$(installedModuleVersion)"
# compute a UTC timestamp variable so every downloadable artifact name is unique per run.
- pwsh: |
$stamp = (Get-Date).ToUniversalTime().ToString('yyyyMMdd_HHmmss')
Write-Host "##vso[task.setvariable variable=artifactStamp;isOutput=true]$stamp"
Write-Host "Artifact timestamp: $stamp"
displayName: 'Compute Artifact Timestamp'
condition: always()
name: stamp
- task: PublishBuildArtifacts@1
displayName: 'Publish Inventory Artifact'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'azlocal-step.1-cluster-inventory_$(stamp.artifactStamp)'
publishLocation: 'Container'