Azure DevOps – Copy Files from git Repository to Azure Storage Account

In this article, we are going to learn how to copy the files from the git repository to an Azure Storage Account.

Prerequisites

  1. A valid Azure Subscription
  2. A valid Azure DevOps Account
  3. Create a Storage account and create a Container named “sourcefiles”. As shown below the container is empty.
0. Azure DevOps - Storage Account - Empty
Azure DevOps – Storage Account – Empty

In this article, we are going to build the following two pipelines using Classic editor. You can follow the same approach even if you would like to create YAML base pipelines.

  1. Build Pipeline – The build pipeline copies the files from Azure DevOps repository to the Azure DevOps artifacts
  2. Release Pipeline – The release pipeline picks the files from the Azure DevOps artifacts to Storage Account.

Let’s start authoring the pipelines

Create an Artifactory:

As shown below, create a set of files in the repository that you would like to copy to Azure Storage account. For the sake of this article, I have created a folder and two files.

Azure DevOps - Git Repository - Static Files
Azure DevOps – Git Repository – Static Files

Create Build Pipeline:

In this section, we will work on creating a Build pipeline for copying the files from the Azure DevOps – Git repository to Azure DevOps antifactory. It’s a two-step process.

StepTaskComments
Step1Copy FilesIn this step, the Copy Files task copies the files from the Azure DevOps repository to a Staging directory $(Build.ArtifactStagingDirectory) of the Agent
Step2Publish Build ArtifactsIn this step, the Publish Build Artifacts task, copies the files from the Staging Directory $(Build.ArtifactStagingDirectory) to the Azure DevOps artifacts from where the Release pipeline could pick.

Below is how it looks once the above two tasks are created.

Step1: Copy files Task

Azure DevOps - Build Pipelines - Copy Files Task
Azure DevOps – Build Pipelines – Copy Files Task

Step1: Publish Build Artifacts Task

Azure DevOps - Build Pipelines - Publish Build Artifacts Task
Azure DevOps – Build Pipelines – Publish Build Artifacts Task

Run the Build Pipeline to quickly validate if everything is working fine. If you see the text 1 published then the Build pipeline is working well. You can also click on 1 Published artifact and see the contents to ensure that the required files are packages as artifact.

Azure DevOps - Build Pipelines - Published Artifact
Azure DevOps – Build Pipelines – Published Artifact

Create Release Pipeline:

Let’s now work on authoring the Release pipeline with an Empty Job and configure the below steps.

Add an Artifact by choosing the Build Pipeline as shown in the below screenshot.

Azure DevOps - Build Pipelines - Add Artifact
Azure DevOps – Build Pipelines – Add Artifact

Step1: Azure File Copy task

In this section, let’s use the Azure File Copy task to copy the files from the Azure DevOps artifacts to Azure Storage Account.

Azure DevOps - Release Pipelines - Azure File Copy
Azure DevOps – Release Pipelines – Azure File Copy

That’s it. We have configured both the Build Pipeline and the Release pipeline. Let’s run the Release pipeline by clicking on Create Release button

In my case, I have faced an error with the message Status: 403 This request is not authorized to perform this operation using this permission as shown below.

Azure DevOps - Release Pipelines - Azure File Copy - Version 4 error
Azure DevOps – Release Pipelines – Azure File Copy – Version 4 error

It looks like there is an error in the Azure File Copy task’s version 4. So, I have changed the version back to 3 as shown below.

Azure DevOps - Release Pipelines - Azure File Copy - Version 3
Azure DevOps – Release Pipelines – Azure File Copy – Version 3

Let’s run the Pipeline again and it worked well as shown below.

Azure DevOps - Release Pipelines - Successful Release
Azure DevOps – Release Pipelines – Successful Release

And, I can see both the files copied into Storage Account as well which is shown below.

Azure DevOps - Storage Account
Azure DevOps – Storage Account

That’s it. We have learnt how to copy the files from Azure DevOps git to Storage Account.

For getting more updates on Azure DevOps, you can join my WhatsApp group at Azure DevOps World 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s