Search code examples
azureazure-devopsazure-pipelinesazure-files

How to copy a file from Azure Storage fileshare to Release pipeline agent


I want to download a file that is on my Azure File storage in FileShare into my release pipeline agent.

enter image description here

Inside the release pipeline I am using a PowerShell step and run the command:

Start-AzStorageFileCopy    -SrcShareName "report.xml" -SrcFilePath "."  -DestFilePath "$(System.DefaultWorkingDirectory)" -DestShareName  "report.xml" -Context $(context)

its asking me now for a parameter -name

2020-05-09T01:43:34.1007773Z ##[error]Cannot process command because of one or more missing mandatory parameters: Name.

Basically my plan is to use this file for a test report in a release pipeline. Therefore I need this file to be used in a Publish Test Result step.

enter image description here


Solution

  • Since you are trying to download single report.xml file from Azure File Share, directly use Get-AzureStorageFileContent command.

    Sample:

    $ctx = New-AzureStorageContext [storageaccountname] [storageaccountkey]
    
    ##sharename is your existed name.
    
    $s = Get-AzureStorageShare [sharename] –Context $ctx
    
    ##To download a file from the share to the local computer, use Get-AzureStorageFileContent.
    
    Get-AzureStorageFileContent –Share $s –Path [path to file on the share] [path on local computer]
    

    If you want to download multiple files using one command, you could use Azcopy.

    More detail info please take a look at this blog.