diff --git a/.drone.yml b/.drone.yml index 13b2892..1cc439d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -57,6 +57,21 @@ steps: path: /output - name: scratch path: /scratch +- name: Remove temporary resources + image: bv11-cr01.bessems.eu/library/packer-extended + commands: + - | + pwsh -file scripts/Remove-Resources.ps1 \ + -VMName '$DRONE_BUILD_NUMBER-${DRONE_COMMIT_SHA:0:10}' \ + -VSphereFQDN 'bv11-vc01.bessems.lan' \ + -VSphereUsername 'administrator@vsphere.local' \ + -VSpherePassword '$${VSPHERE_PASSWORD}' + environment: + VSPHERE_PASSWORD: + from_secret: vsphere_password + volumes: + - name: scratch + path: /scratch - name: Trigger downstream builds image: plugins/downstream settings: diff --git a/packer/windowsserver2019.json b/packer/windowsserver2019.json index aaa7d19..e35cc5c 100644 --- a/packer/windowsserver2019.json +++ b/packer/windowsserver2019.json @@ -227,18 +227,5 @@ " /output/Windows-Server-2019-LTSC.ova" ] } - ], - [ - { - "type": "shell-local", - "inline": [ - "pwsh -file scripts/Remove-Resources.ps1 \\", - " -VMName '{{user `vm_guestos`}}-{{user `vm_name`}}' \\", - " -VSphereFQDN '{{user `vcenter_server`}}' \\", - " -VSphereUsername '{{user `vsphere_username`}}' \\", - " -VSpherePassword '{{user `vsphere_password`}}' \\", - " -BuildName '{{build_name}}'" - ] - } ]] } diff --git a/scripts/Remove-Resources.ps1 b/scripts/Remove-Resources.ps1 index 05ba9be..9c68dac 100644 --- a/scripts/Remove-Resources.ps1 +++ b/scripts/Remove-Resources.ps1 @@ -8,8 +8,6 @@ Param( [string]$VSphereUsername, [Parameter(Mandatory)] [string]$VSpherePassword, - [Parameter(Mandatory)] - [string]$BuildName ) $PowerCliConfigurationSplat = @{ @@ -29,7 +27,7 @@ $ConnectVIServerSplat = @{ Connect-VIServer @ConnectVIServerSplat | Out-Null $GetVMSplat = @{ - Name = "$($VMName)*" + Name = "*$($VMName)*" ErrorAction = 'SilentlyContinue' } If ([boolean](Get-VM @GetVMSplat)) { @@ -45,7 +43,7 @@ If ([boolean](Get-VM @GetVMSplat)) { Disconnect-VIServer * -Confirm:$False $RemoveItemSplat = @{ - Path = "/scratch/$($BuildName)/*" + Path = "/scratch/*" Recurse = $True Force = $True Confirm = $False