Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pipeline to cleanup PR environments #3236

Merged
merged 5 commits into from
May 12, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions build/cleanup-pr-environments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# DESCRIPTION:
# Removes resource groups used in PRs.
# THIS WILL DELETE ALL PR RESOURCE GROUPS, EVEN THOSE CURRENTLY RUNNING.
# Check that no PRs are currently running and no one needs any of the resource groups before running.
ukachiokoli marked this conversation as resolved.
Show resolved Hide resolved
# The Exclude variable can be used to preserve specific resource groups. It is a comma seperated list of the full resource group names.

variables:
- template: build-variables.yml
- template: pr-variables.yml

stages:
- stage: CleanupRGs
displayName: 'Cleanup Resource Groups'
jobs:
- job: DeleteResourceGroup
displayName: 'Delete resource group'
pool:
name: '$(SharedLinuxPool)'
vmImage: '$(LinuxVmImage)'
steps:
- task: AzurePowerShell@4
displayName: 'Delete resource group'
inputs:
azureSubscription: $(ConnectedServiceName)
azurePowerShellVersion: latestVersion
ScriptType: InlineScript
Inline: |
$excludeList = ${env:Exclude}.Split(',').Trim()
Get-AzResourceGroup -Name "$(resourceGroupRoot)*" -Location "$(ResourceGroupRegion)" | Where ResourceGroupName -NotIn $excludeList | Remove-AzResourceGroup -Verbose -Force