-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathmanagedimage-cleanup-template.yml
More file actions
67 lines (62 loc) · 2.59 KB
/
Copy pathmanagedimage-cleanup-template.yml
File metadata and controls
67 lines (62 loc) · 2.59 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
parameters:
- name: variable_group_name
displayName: Variable Group
type: string
default: 'Image Generation Variables'
- name: agent_pool
displayName: Agent Pool
type: string
default: CI Windows2022
- name: gallery_images_to_keep
displayName: Number of image versions to keep in gallery
type: number
default: 3
- name: repository_base_path
displayName: Scripts Path
type: string
default: .
stages:
- stage: delete_gallery_imagevm
displayName: 'Delete Gallery Image Version VM'
jobs:
- job: cleanupobsoletevmrunnerimages
displayName: 'Cleanup obsolete VM Gallery runner images'
pool:
name: ${{ parameters.agent_pool }}
variables:
- group: ${{ parameters.variable_group_name }}
steps:
- checkout: self
- ${{ if ne(parameters.repository_base_path, '.') }}:
- checkout: ${{ parameters.repository_base_path }}
- task: PowerShell@2
name: setVars
displayName: 'Set image template variables'
inputs:
targetType: 'inline'
script: |
$client_id = "$(DOBA-CLIENT-ID)"
$client_secret = "$(DOBA-CLIENT-SECRET)"
$tenant_id = "$(DOBA-TENANT-ID)"
$subscription_id = "$(DOBA-SUBSCRIPTION-ID)"
$gallery_name = "$(DOBA-GALLERY-NAME)"
$gallery_rg_name = "$(DOBA-GALLERY-RESOURCE-GROUP)"
Write-Host "##vso[task.setvariable variable=client_id]$client_id"
Write-Host "##vso[task.setvariable variable=client_secret;isSecret=true]$client_secret"
Write-Host "##vso[task.setvariable variable=tenant_id]$tenant_id"
Write-Host "##vso[task.setvariable variable=subscription_id]$subscription_id"
Write-Host "##vso[task.setvariable variable=gallery_name]$gallery_name"
Write-Host "##vso[task.setvariable variable=gallery_rg_name]$gallery_rg_name"
- task: PowerShell@2
displayName: 'Remove obsolete VM Gallery runner Images'
inputs:
targetType: filePath
filePath: ${{ parameters.repository_base_path }}/scripts/cleanup-gallery-vmimageversion.ps1
arguments: -ClientId $(DOBA-CLIENT-ID) `
-ClientSecret $(DOBA-CLIENT-SECRET) `
-SubscriptionId $(DOBA-SUBSCRIPTION-ID) `
-TenantId $(DOBA-TENANT-ID) `
-GalleryName $(DOBA-GALLERY-NAME) `
-GalleryResourceGroup $(DOBA-GALLERY-RESOURCE-GROUP) `
-GalleryImagesToKeep ${{ parameters.gallery_images_to_keep }} `
-ImageDefinitions @("ubuntu2204-agentpool-full", "ubuntu2404-agentpool-full", "windows2022-agentpool-full", "windows2025-agentpool-full")