如何从 Azure DevOps 管道读取 Azure 文件共享文件
How to Read Azure File Share Files from Azure DevOps Pipeline
我目前已经创建了一个 Azure 存储帐户。在此存储内部,我创建了两个文件共享。我已将文件上传到每个文件共享中,并希望从 Azure DevOps 管道中访问这些文件。
我在网上研究了如何执行此操作,但没有找到详细说明如何执行此操作的资源。有没有人这样做过?如果是,从 azure devOps 管道读取文件共享文件的步骤是什么?
谢谢。
有人问
would like to access these files from within the Azure DevOps pipeline
您可以尝试使用 AzCopy 命令 copy/download 从 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
我找到了使用 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()
我目前已经创建了一个 Azure 存储帐户。在此存储内部,我创建了两个文件共享。我已将文件上传到每个文件共享中,并希望从 Azure DevOps 管道中访问这些文件。
我在网上研究了如何执行此操作,但没有找到详细说明如何执行此操作的资源。有没有人这样做过?如果是,从 azure devOps 管道读取文件共享文件的步骤是什么?
谢谢。
有人问
would like to access these files from within the Azure DevOps pipeline
您可以尝试使用 AzCopy 命令 copy/download 从 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
我找到了使用 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()