-
Notifications
You must be signed in to change notification settings - Fork 44
/
azure-pipelines-PR-cleanup.yaml
47 lines (38 loc) · 1.44 KB
/
azure-pipelines-PR-cleanup.yaml
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
trigger: # Trigger the pipeline only when a PR is merged into master branch
- master
pr:
- none
variables:
imageRepository: 'collab'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: AzureCLI@2
displayName: PR environment cleanup
inputs:
azureSubscription: $(azSubServiceConnection)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
ACR_IMAGES=$(az acr repository list -n $ACR_NAME | grep collab)
OPEN_PRS=$(curl -L -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/gctools-outilsgc/gcconnex/pulls | grep \"number\")
echo $ACR_IMAGES
echo $OPEN_PRS
for image in $ACR_IMAGES; do
pr_number=$(echo $image | grep -o "[0-9]\+")
echo $pr_number
is_open=$(echo $OPEN_PRS | grep -c ": $pr_number,")
echo $is_open
if [ $is_open = 0 ]; then
echo "$pr_number cleanup"
az group delete --name collab_review_$pr_number --yes
az mysql flexible-server db delete -g $DBRG -s $DBSERVERNAME --database-name gccollab-pr-$pr_number --yes
az mysql flexible-server db delete -g $DBRG -s $DBSERVERNAME --database-name gcconnex-pr-$pr_number --yes
az acr repository delete --name $ACR_NAME --repository collab_pr-$pr_number --yes
fi
done
env:
DBRG: $(db_resource_group)
DBSERVERNAME: $(review_db_server_name)
ACR_NAME: $(acrName)
LOCATION: $(location)