簡體   English   中英

如何從 Azure DevOps 管道讀取 Azure 文件共享文件

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

我目前已經創建了一個 Azure 存儲帳戶。 在這個存儲中,我創建了兩個文件共享。 我已將文件上傳到每個文件共享中,並希望從 Azure DevOps 管道中訪問這些文件。

我在網上研究了如何做到這一點,並沒有找到詳細說明如何做到這一點的資源。 有沒有人這樣做過? 如果是,從 azure devOps 管道讀取文件共享文件的步驟是什么?

謝謝。

人們問

想從 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

您可以在本文檔中找到更多信息:

快速入門:使用 PowerShell 上傳、下載和列出 Blob

我找到了一個使用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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM