How can I download a file from blob storage inside an Azure pipeline?
Asked Answered
H

1

16

I'm trying to download a file I've uploaded to Azure blob storage which I want to use during an Azure Pipelines build.

I am using the windows-latest Microsoft-hosted vm to build.

I've tried making a powershell script and using azcopy, but I haven't been able to get it to authenticate. I've tried looking through the documentation but there are so many terms, acronyms, and different ways of doing things, that I am lost. It seems that since I am using a vm provided by Azure, I should be able to somehow use the built-in authentication without having to pass credentials, but I can't figure that out. I tried azcopy login --identity but that didn't work either. I've also tried running through Azure Powershell, but that didn't make a difference

In one part of my pipeline I use the tool installer task for installing the java JDK--all I have to do is pass it a Service Connection and it works without problems. Both the JDK and the installer are in the same blob, so can I somehow use the Service Connection to authenticate?

Hua answered 24/7, 2020 at 23:20 Comment(0)
S
15

You can try to execute az storage blob download command in Azure cli task to download files from Azure Blob Storage:

steps:
- task: AzureCLI@1
  displayName: 'Azure CLI '
  inputs:
    azureSubscription: {service connection}
    scriptLocation: inlineScript
    inlineScript: |
     mkdir $(Build.SourcesDirectory)\BlobFile
     az storage blob download --container-name $(containername) --file $(Build.SourcesDirectory)\BlobFile --name "{file name}" --account-key $(accountkey) --account-name $(accountname)

Using mkdir to create a folder in current directory, then download file from blob and save it into this folder. Service connection is integrated into this task, so you can configure the service connection to connect to your Azure blob. Then select it in this Azure cli task.

Stilt answered 27/7, 2020 at 3:32 Comment(1)
I had to add the script type to get it to work: learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/… scriptType: psConvincing

© 2022 - 2024 — McMap. All rights reserved.