【问题标题】:How to Read Azure File Share Files from Azure DevOps Pipeline如何从 Azure DevOps Pipeline 读取 Azure 文件共享文件
【发布时间】:2020-11-06 09:24:30
【问题描述】:

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

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

谢谢。

人们问

【问题讨论】:

  • Stack Overflow 不是代码编写服务。在寻求帮助之前,您需要自己做出合理的尝试来解决问题。
  • 不需要被动攻击性的陈述,因为它不能解决问题,只会造成紧张,让你在社区中看起来很糟糕。
  • 这个问题很好,因为在这种情况下你无法编写代码,当你无法弄清楚解决问题的方法时。顺便说一句:我今天脑子里也有完全相同的问题。感谢您提出这个问题和答案(-:

标签: azure azure-devops azure-storage azure-pipelines azure-files


【解决方案1】:

希望从 Azure DevOps 管道中访问这些文件

您可以尝试使用 AzCopy 命令 将这两个文件共享从 Azure blob 复制/下载到 Azure DevOps Pipeline:

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

您可以在此文档中找到更多信息:

Quickstart: Upload, download, and list blobs with PowerShell

【讨论】:

  • 谢谢利奥。将查看此资源。
【解决方案2】:

我找到了使用Microsoft Azure File Share Storage Client Library for Python 的解决方案。我在 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()

【讨论】:

  • 太棒了!感谢您在这里分享您的解决方案,您可以 Accept it as an Answer ,这样它可以帮助遇到相同问题的其他社区成员,我们可以归档这个帖子,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
  • 2016-07-03
  • 2021-12-26
  • 2020-12-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多