From 556b270e7a1edea8dd1b657f2e099cd7f5fd9cfe Mon Sep 17 00:00:00 2001 From: narrieta Date: Mon, 8 Jan 2024 11:48:35 -0800 Subject: [PATCH 1/3] Install missing dependency (jq) on Azure Pipeline Agents --- tests_e2e/pipeline/pipeline-cleanup.yml | 11 +++++++---- tests_e2e/pipeline/scripts/setup-agent.sh | 6 +++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests_e2e/pipeline/pipeline-cleanup.yml b/tests_e2e/pipeline/pipeline-cleanup.yml index c800c1c6ab..87e2d827b0 100644 --- a/tests_e2e/pipeline/pipeline-cleanup.yml +++ b/tests_e2e/pipeline/pipeline-cleanup.yml @@ -45,12 +45,15 @@ steps: rest_endpoint=$(az cloud show --query "endpoints.resourceManager" -o tsv) + pattern="${{ parameters.name_pattern }}" + az rest --method GET \ --url "${rest_endpoint}/subscriptions/${subscription_id}/resourcegroups" \ --url-parameters api-version=2021-04-01 \$expand=createdTime \ --output json \ --query value \ - | jq --arg date "$date" '.[] | select (.createdTime < $date).name' \ - | grep -i '${{ parameters.name_pattern }}' \ - | xargs -l -t -r az group delete --no-wait -y -n \ - || echo "No resource groups found to delete" + | jq --arg date "$date" '.[] | select (.createdTime < $date).name | match("'${pattern}'"; "g").string' \ + | xargs -l -t -r az group delete --subscription "${subscription_id}" --no-wait -y -n \ + | tee deleted + + [ -s deleted ] || echo "No resource groups found to delete" diff --git a/tests_e2e/pipeline/scripts/setup-agent.sh b/tests_e2e/pipeline/scripts/setup-agent.sh index 5990ada0ac..9b1316059a 100755 --- a/tests_e2e/pipeline/scripts/setup-agent.sh +++ b/tests_e2e/pipeline/scripts/setup-agent.sh @@ -18,7 +18,7 @@ # # -# Script to setup the agent VM for the Azure Pipelines agent pool; it simply installs the Azure CLI and the Docker Engine. +# Script to setup the agent VM for the Azure Pipelines agent pool; it simply installs the Azure CLI, the Docker Engine and jq. # set -euox pipefail @@ -48,3 +48,7 @@ sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plug # Verify that Docker Engine is installed correctly by running the hello-world image. sudo docker run hello-world + +# Install jq; it is used by the cleanup pipeline to parse the JSON output of the Azure CLI +sudo apt-get install -y jq + From bf695a4262da9cf35a27862eae0874f5f0646364 Mon Sep 17 00:00:00 2001 From: narrieta Date: Mon, 8 Jan 2024 12:01:20 -0800 Subject: [PATCH 2/3] use if statement --- tests_e2e/pipeline/pipeline-cleanup.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests_e2e/pipeline/pipeline-cleanup.yml b/tests_e2e/pipeline/pipeline-cleanup.yml index 87e2d827b0..f079c6ee1d 100644 --- a/tests_e2e/pipeline/pipeline-cleanup.yml +++ b/tests_e2e/pipeline/pipeline-cleanup.yml @@ -56,4 +56,8 @@ steps: | xargs -l -t -r az group delete --subscription "${subscription_id}" --no-wait -y -n \ | tee deleted - [ -s deleted ] || echo "No resource groups found to delete" + if [ ! -s deleted ] + then + echo "No resource groups found to delete" + fi + From 20f9b79881c48786cfd6080becb53b425cae0c5d Mon Sep 17 00:00:00 2001 From: narrieta Date: Mon, 8 Jan 2024 12:13:55 -0800 Subject: [PATCH 3/3] remove if statement --- tests_e2e/pipeline/pipeline-cleanup.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests_e2e/pipeline/pipeline-cleanup.yml b/tests_e2e/pipeline/pipeline-cleanup.yml index f079c6ee1d..7f9f57a6c6 100644 --- a/tests_e2e/pipeline/pipeline-cleanup.yml +++ b/tests_e2e/pipeline/pipeline-cleanup.yml @@ -53,11 +53,4 @@ steps: --output json \ --query value \ | jq --arg date "$date" '.[] | select (.createdTime < $date).name | match("'${pattern}'"; "g").string' \ - | xargs -l -t -r az group delete --subscription "${subscription_id}" --no-wait -y -n \ - | tee deleted - - if [ ! -s deleted ] - then - echo "No resource groups found to delete" - fi - + | xargs -l -t -r az group delete --subscription "${subscription_id}" --no-wait -y -n