本文介绍了如何从Azure DevOps管道读取Azure文件共享文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I currently have created an Azure storage account. 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?

谢谢.

人们问

推荐答案

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

I found a solution using the 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. 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()

这篇关于如何从Azure DevOps管道读取Azure文件共享文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 21:17
查看更多