如何从 Azure DevOps Pipeline 读取 Azure 文件共享文件

gre*_*ars 5 azure azure-storage azure-files azure-devops azure-pipelines

我目前已经创建了一个 Azure 存储帐户。在这个存储中,我创建了两个文件共享。我已将文件上传到每个文件共享中,并希望从 Azure DevOps 管道中访问这些文件。

我在网上研究过如何做到这一点,但没有找到详细说明如何做到这一点的资源。以前有人这样做过吗?如果是,从 azure devOps 管道读取文件共享文件的步骤是什么?

谢谢。

人们问

gre*_*ars 2

我找到了一个使用适用于 Python 的 Microsoft Azure 文件共享存储客户端库的解决方案。我在 Azure 管道中运行了以下步骤来连接到我的文件共享。以下是连接到文件共享并共享其所有内容的示例:

    - 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()
Run Code Online (Sandbox Code Playgroud)