简体   繁体   English

如何从 Azure DevOps 管道读取 Azure 文件共享文件

[英]How to Read Azure File Share Files from Azure DevOps Pipeline

I currently have created an Azure storage account.我目前已经创建了一个 Azure 存储帐户。 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.我已将文件上传到每个文件共享中,并希望从 Azure DevOps 管道中访问这些文件。

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?如果是,从 azure devOps 管道读取文件共享文件的步骤是什么?

Thanks.谢谢。

People asked人们问

would like to access these files from within the Azure DevOps pipeline想从 Azure DevOps 管道中访问这些文件

You could try to use AzCopy command to copy/download those two file shares from Azure blob to Azure DevOps Pipeline:您可以尝试使用AzCopy 命令将这两个文件共享从 Azure blob 复制/下载到 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 快速入门:使用 PowerShell 上传、下载和列出 Blob

I found a solution using the Microsoft Azure File Share Storage Client Library for Python .我找到了一个使用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.我在 Azure 管道中运行了以下步骤以连接到我的文件共享。 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM