Skip to content

Commit

Permalink
Task: reusables scripts pipeline agnostic (#24)
Browse files Browse the repository at this point in the history
* feat: reusable script upload test assets

* feat: update for folder or single

* docs: update readme
  • Loading branch information
estherthetesteramido authored Jun 16, 2020
1 parent f05e61e commit c99243f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scripts/test/README.md
Original file line number Diff line number Diff line change
@@ -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.
29 changes: 29 additions & 0 deletions scripts/test/upload-azstorage-blob.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit c99243f

Please sign in to comment.