首页 > 解决方案 > 使用 Azure Pipeline 时如何将文件复制到 Azure Blob

问题描述

我已经尝试了很多次,但仍然出现如下错误:

“管道无效。作业作业:步骤 AzureFileCopy 输入 ConnectedServiceNameARM 引用服务连接 xxxxx-xxx-xx-xxxx-xxxxxxxx 无法找到。服务连接不存在或未被授权使用。授权详情,请参阅https://aka.ms/yamlauthz。”

在右侧,有一个“授权资源”按钮。但是无论我如何单击它,它都会显示“自动授权资源时发生错误”

这是我的 yaml 文件的一部分:

task: AzureFileCopy@3
inputs: 
    sourcePath:'AddFunction/bin/Debug/AddFunction.exe' 
    azureSubscription:'xxxxxx-xxxx-xxxx-xxxx-xxxxxxx' 
    destination: AzureBlob 
    storage:'1234' 
    containerName: 'test'

我还连接了 Azure Pipeline 上的服务连接,并为我的资源类型选择了“Azure 资源管理器”。

任何想法或指针将不胜感激。

标签: azureyaml

解决方案


如果要将文件上传到 Azure Blob,可以通过 Azure Cli 在 Powershell 脚本中执行完全相同的操作,并通过 Azure Pipeline 中的 Powershell 任务触发它。

# PowerShell
# Run a PowerShell script on Linux, macOS, or Windows
- task: PowerShell@2
  inputs:
    #targetType: 'filePath' # Optional. Options: filePath, inline
    #filePath: # Required when targetType 

Powershell 脚本就像

#First, You have to login with a service principal.
az login --service-principal -u $AZ_NAME -p $AZ_PWD --tenant $AZ_TENANT

#upload your file by az storage blob 
az storage blob upload --container-name $container_name --file $file_to_upload --name $blob_name

这可能不是完美的答案,但我希望它可以帮助您并挽救您的一天。


推荐阅读