Created
September 26, 2022 20:46
-
-
Save bartekpacia/194b801a4a3bd050641b806957b3224e to your computer and use it in GitHub Desktop.
Shell script to easily upload a file to Azure Storage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# upload_artifact uploads a file to Azure Storage. | |
# | |
# Usage: | |
# | |
# AZURE_SAS_TOKEN=SOME_TOKEN ./upload_artifact your_file.txt | |
artifact="${1:-}" | |
if [ -z "$artifact" ]; then | |
echo "File to be uploaded was not passed as the first argument" | |
exit 1 | |
fi | |
mime="$(file -b --mime-type "$artifact")" | |
if [ -z "${AZURE_STORAGE_URL:-}" ]; then | |
echo "AZURE_STORAGE_URL is not set" | |
exit 1 | |
fi | |
if [ -z "${AZURE_SAS_TOKEN:-}" ]; then | |
echo "AZURE_SAS_TOKEN is not set" | |
exit 1 | |
fi | |
filename="$(basename "$artifact")" | |
url="$AZURE_STORAGE_URL/$filename?$AZURE_SAS_TOKEN" | |
echo "File $filename will be uploaded to $url" | |
curl --location -g --request PUT "$url" \ | |
--header "x-ms-blob-type: BlockBlob" \ | |
--header "Content-Type: $mime" \ | |
--data-binary "@$PWD/$artifact" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment