Coping folder from Azure DevOps to an Azure Storage using a Yaml pipeline

Tzahi Kolber
3 min readSep 22, 2022

In this blog I will review a short script which allows you to copy folder from the Azure DevOps repository (Repos) to a storage account’s container in Azure.

Pipeline overview

The Yaml file includes parameters that can be changed and allows you enter different names for the resource group, storage and container, so you would not have to edit the file each time you would like to copy a folder from the Repos to other resource group, storage or container.

According to the parameters configured above, the Yaml file runs the following actions:

  1. Create a SAS token which expires in 2 minutes.
  2. Get the Storage account’s key.
  3. Create a container, based on the parameters that were entered (in case it doesn’t exist), at the resource group and storage.
  4. The script also lists the files at the chosen folder you wish to copy to Azure container:

5. In case the storage is blocked from network access by IP network rules of the storage account, the pipeline gets the Azure DevOps current IP address and add it to the whitelist, so it will be able to access the storage.

6. Since it might take around 30 seconds to update the storage account whitelist, I have added a pause of 45 seconds after adding the DevOps IP address to the storage network rules.
By the way, decreasing this delay, might cause the pipeline failed from time to time, to create or update the container and copying the files from Repos:

This example shows one of the pipelines running where the delay was smaller than 45 seconds.
Looks like the IP address was added to the storage account whitelist, but actually it didn’t update and enforced.

7. After setting up the container and networking configuration, the pipeline uploads a folder, from an existing Repos folder.
In this case templates folder: “$(System.DefaultWorkingDirectory)/templates

Of course, it can be changed according to your folder structure.

8. By default, the script overwrites the content of the container in case it exists.
If you would like to cancel this option, set the next part of the line from true to false:
“$(System.DefaultWorkingDirectory)/templates” — overwrite true

8. At the end of the pipeline, the process removes the Azure DevOps IP address from the whitelist:

  • The source directory (Azure DevOps):
  • The destination container:

The Yaml file

Click the link below to get the script:

--

--

Tzahi Kolber

During the last 15 years, I was working as a Senior PFE within Exchange area at Microsoft. Now I’m Senior Consult as Azure IAAS, PowerShell & Automations.