Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Read Azure File Share Files from Azure DevOps Pipeline

I currently have created an Azure storage account. Inside of this storage, I've created two file shares. I've uploaded files into each file share, and would like to access these files from within the Azure DevOps pipeline.

I've researched online how to do this, and have not found a resource detailing how to do this. Has anyone done this before? If yes, what are the steps to read file share files from an azure devOps pipeline?

Thanks.

People asked

like image 473
green-mars Avatar asked Jul 16 '20 16:07

green-mars


People also ask

Which file protocols can be used to access Azure file shares?

Azure Files offers two industry-standard protocols for mounting Azure file share: the Server Message Block (SMB) protocol and the Network File System (NFS) protocol.

Can I access Azure file share from browser?

From your application, you can use storage client libraries, REST APIs, PowerShell, or Azure CLI to access your files in the Azure file share. A file share can be accessed via browser if the application uses REST APIs.

How does Azure file share work?

An Azure file share is a convenient place for cloud applications to write their logs, metrics, and crash dumps. Logs can be written by the application instances via the File REST API, and developers can access them by mounting the file share on their local machine.


2 Answers

would like to access these files from within the Azure DevOps pipeline

You could try to use AzCopy command to copy/download those two file shares from Azure blob to Azure DevOps Pipeline:

azcopy login
azcopy copy /Source:https://myaccount.file.core.windows.net/myfileshare/myfolder/ /Dest:$(Build.SourcesDirectory)\myfolder

You can find more info in this document:

Quickstart: Upload, download, and list blobs with PowerShell

like image 98
Leo Liu-MSFT Avatar answered Oct 25 '22 00:10

Leo Liu-MSFT


I found a solution using the Microsoft Azure File Share Storage Client Library for Python. I ran the following steps inside of my Azure pipeline to connect to my File Share. Below is an example that connects to the file share and shares all its contents:

    - task: UsePythonVersion@0
      displayName: 'Set Python 3.8.3'
      inputs:
        versionSpec: 3.8.3
        addToPath: true
      name: pyTools

    - script: $(pyTools.pythonLocation)/bin/pip3 install azure-storage-file-share
      displayName: Install azure-storage-file-share module
        
    - task: PythonScript@0
      displayName: Show files and directories inside of File Share
      inputs:
        scriptSource: 'inline'
        script: |
          import platform
          from azure.storage.fileshare import ShareDirectoryClient

          connection_string = "DefaultEndpointsProtocol=https;AccountName=<storage-name>;AccountKey=<access-key>==;EndpointSuffix=core.windows.net"
          parent_dir = ShareDirectoryClient.from_connection_string(conn_str=connection_string, share_name=<file-share-name>, directory_path="")

          my_list = list(parent_dir.list_directories_and_files())
          print(my_list)
          print(platform.python_version()
like image 26
green-mars Avatar answered Oct 24 '22 23:10

green-mars