Action-AzureBlobUpload icon indicating copy to clipboard operation
Action-AzureBlobUpload copied to clipboard

A GitHub action to upload files to Azure Blob storage, compatible with all Actions runner operating systems.

Azure Blob Upload

This GitHub Action a simple and easy way to upload any files to any blob container.

Workflow Status
main and releases Main and Releases

Inputs

Below are the action's inputs that need to be defined in the Action's with block.

Required Inputs Example Summary
connection_string ${{ secrets.MyCnnStr }} Azure Blob Storage conection string (for help, visit View Account Access Keys).
container_name my-container Name of the Blob container.
source_folder src\LocalFolderName\ Folder with the files to upload. Note that the path separators will be automatically be normalized for you.
destination_folder MyTargetFolder/Subfolder Folder to upload to (it will be created for you if it does not exist).
clean_destination_folder false (default) Delete all destination files before uploading new ones.
fail_if_source_empty false (default) Set to true if you want action to fail if source folder has no files.
is_recursive true (default) Set to false if you want all subfolders ignored.
delete_if_exists false (default) Set to true if you want to overwrite an exiting blob with the same filename.

Examples

If you copy-paste from the examples below, don't forget to use a real version number at the end of action name. For example, an exact version number LanceMcCarthy/[email protected], or you can use the 'latest version' tag LanceMcCarthy/Action-AzureBlobUpload@v2.

Basic Use

In the most basic form, the Action will upload all the files in the source_folder to the root of that blob container.

- uses: LanceMcCarthy/Action-AzureBlobUpload@v2
  name: Uploading to Azure storage...
  with:
    connection_string: ${{ secrets.YourAzureBlobConnectionString }}
    container_name: your-container-name
    source_folder: src\LocalFolderName\

Set a Destination Folder (most common)

If you want to upload the files to a folder in the blob container, you can set a destination_folder.

In this example, we use clean_destination_folder, which gives you a clean start for the entire operation.

- uses: LanceMcCarthy/Action-AzureBlobUpload@v2
  name: Azure Blob Upload with Destination folder defined
  with:
    connection_string: ${{ secrets.YourAzureBlobConnectionString }}
    container_name: your-container-name
    source_folder: src\LocalFolderName\
    destination_folder: FolderNameInAzureStorage
    clean_destination_folder: true

Alternatively, you can use delete_if_exists if you only want to overwrite some files, but keep the rest.

- uses: LanceMcCarthy/Action-AzureBlobUpload@v2
  name: Azure Blob Upload with Destination folder defined
  with:
    connection_string: ${{ secrets.YourAzureBlobConnectionString }}
    container_name: your-container-name
    source_folder: src\LocalFolderName\
    destination_folder: FolderNameInAzureStorage
    delete_if_exists: true

Ignore Subfolder

If you want to upload only files in the source_folder and skip subfolders and subfolder files, set is_recursive to false.

- name: Upload Text Files Non-recursive
  uses: LanceMcCarthy/Action-AzureBlobUpload@v2
  with:
    connection_string: ${{ secrets.AzureBlobConnectionString }}
    container_name: your-container-name
    source_folder: src\LocalFolderName\
    destination_folder: FolderNameInAzureStorage
    clean_destination_folder: true
    is_recursive: false

Single File Mode

You can set the source_folder to a single file path to upload only one file. For example, this one uploads MySingleFileApplication.exe.

- uses: LanceMcCarthy/Action-AzureBlobUpload@v2
  name: Azure Blob Upload with Destination folder defined
  with:
    connection_string: ${{ secrets.YourAzureBlobConnectionString }}
    container_name: your-container-name
    source_folder: src\LocalFolderName\MySingleFileApplication.exe
    destination_folder: FolderNameInAzureStorage

Advanced - Full Control

Here is an example that might represent a real-world Workflow that needs precise control over things.

  • The source folder uses an environment variable uses (see Using Variables in Actions).
  • The connection string uses a secrets variable.
  • The desination folder combines a name and the run number of the workflow (see GitHub Context variables).
  • The action will fail and stop the Workflow if there are no files to upload.
- uses: LanceMcCarthy/Action-AzureBlobUpload@v2
  name: Azure Blob Upload with Destination folder defined
  with:
    connection_string: ${{ secrets.DeploymentsBlobConnectionString }}
    container_name: my-cd-container
    source_folder: ${{ env.BuildOutputFolder }}
    destination_folder: Distributions/${{ github.run_number }}
    clean_destination_folder: true
    fail_if_source_empty: true

Important Notes

Environment Variables

If you need to use a environment variable for a with input, you must use the ${{ env.Name }} syntax and not $env:Name. See Github Contexts documentation for more help.

For example:

with:
  source_folder: $env:MyVariable # Does NOT work in with assignments.
  source_folder: ${{ env.MyVariable }} # Works.