From c99243f26ddd21ed855efa67642e8980ab6baf11 Mon Sep 17 00:00:00 2001 From: Esther Lloyd <47354603+estherthetesteramido@users.noreply.github.com> Date: Tue, 16 Jun 2020 12:53:01 +0100 Subject: [PATCH] Task: reusables scripts pipeline agnostic (#24) * feat: reusable script upload test assets * feat: update for folder or single * docs: update readme --- scripts/test/README.md | 23 +++++++++++++++++++++ scripts/test/upload-azstorage-blob.sh | 29 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 scripts/test/README.md create mode 100755 scripts/test/upload-azstorage-blob.sh diff --git a/scripts/test/README.md b/scripts/test/README.md new file mode 100644 index 00000000..f70258ba --- /dev/null +++ b/scripts/test/README.md @@ -0,0 +1,23 @@ +# Scripts: CI/CD Pipelines for Test + +## Scripts + +### [upload-azstorage-blob.sh](./upload-azstorage-blob.sh) + +Input: Azure Blob Storage Destination and authentication +Output: Uploads 1 or more files (or whole folder) of assets to Blob. + +#### Example 1: Upload a folder or directory + +`> ./upload-azstorage-blob.sh amido-stacks-rg-uks-dev amidostacksuksdev testresults /Users/estherlloyd/Documents/Github/stacks/stacks-webapp-template/packages/scaffolding-cli/templates/test/cypress-typescript-coreui/results/` + +#### Example 2: Upload a specific file(s) using patterns + +The pattern used for globbing files or blobs in the source. The supported patterns are '*', '?', '[seq]', and '[!seq]'. For more information, please refer to [fnmatch docs](https://docs.python.org/3.7/library/fnmatch.html). + +`> ./upload-azstorage-blob.sh amido-stacks-rg-uks-dev amidostacksuksdev testresults /Users/estherlloyd/Documents/Github/stacks/stacks-webapp-template/packages/scaffolding-cli/templates/test/cypress-typescript-coreui/results/ *report.html` + +## FAQ + +Q: Why is `Please run 'az login' to setup account.` occurring? +A: If you haven't authenticated, then you need to login in to be able to resolve the Account Key. Please run `az login` or authenticate using an alternative method. See [azure-cli sign-in](https://docs.microsoft.com/en-gb/cli/azure/get-started-with-azure-cli?view=azure-cli-latest#sign-in) for more. \ No newline at end of file diff --git a/scripts/test/upload-azstorage-blob.sh b/scripts/test/upload-azstorage-blob.sh new file mode 100755 index 00000000..e8fe00ba --- /dev/null +++ b/scripts/test/upload-azstorage-blob.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Pipeline independent script that can be used for uploading test results to `Blob Storage` + +resource_group_name="$1" +azure_storage_account="$2" +azure_storage_container="$3" +local_source_path="$4" +local_source_file_pattern="${5:-**/*.*}" + +echo "Azure Details:" +echo "Resource group name = $resource_group_name" + +echo "-----" +echo "Upload Details:" +echo "Storage Account Name = $azure_storage_account" +echo "Container Name = $azure_storage_container" +echo "Source Filepath = $local_source_path" +echo "Source Filepattern = $local_source_file_pattern" + +echo "=======" + +echo "Retrieving Storage Account Key" +export ACCOUNT_KEY=$(az storage account keys list -g $resource_group_name -n $azure_storage_account --query '[1].value') + +echo "Uploading Artefact" +az storage blob upload-batch --account-name $azure_storage_account --account-key $ACCOUNT_KEY -d $azure_storage_container -s $local_source_path --pattern $local_source_file_pattern + +echo "Done"