如何从Azure管道内的Blob存储中下载文件? [英] How can I download a file from blob storage inside an Azure pipeline?

查看:73
本文介绍了如何从Azure管道内的Blob存储中下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试下载一个已上传到Azure blob存储的文件,该文件要在Azure Pipelines构建期间使用.

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

我正在使用 windows-latest Microsoft托管的vm​​进行构建.

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

我尝试制作Powershell脚本并使用 azcopy ,但是我无法对其进行身份验证.我试图浏览文档,但是有太多的术语,首字母缩写词和不同的处理方式,让我迷失了方向.看来,由于我使用的是Azure提供的虚拟机,因此我应该能够以某种方式使用内置身份验证,而不必通过凭据,但我无法弄清楚.我尝试了 azcopy login --identity ,但这也不起作用.我也尝试通过Azure Powershell运行,但这没什么作用

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

在我的管道的一部分中,我使用工具安装程序任务来安装Java JDK-我要做的就是将服务连接传递给它,并且它可以正常工作.JDK和安装程序都在同一个Blob中,所以我可以以某种方式使用服务连接进行身份验证吗?

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?

推荐答案

您可以尝试执行

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)

使用 mkdir 在当前目录中创建一个文件夹,然后从blob下载文件并将其保存到该文件夹​​中.服务连接已集成到此任务中,因此您可以配置服务连接以连接到Azure blob.然后在此Azure cli任务中选择它.

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.

这篇关于如何从Azure管道内的Blob存储中下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆