【问题标题】:How to copy file to Azure Blob when using Azure Pipeline使用 Azure Pipeline 时如何将文件复制到 Azure Blob
【发布时间】:2019-11-23 17:18:35
【问题描述】:

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

"管道无效。Job Job: Step AzureFileCopy input 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 资源管理器”。

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

【问题讨论】:

    标签: azure yaml


    【解决方案1】:

    如果要将文件上传到 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
    

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

    【讨论】:

    • 请注意,Lunix 代理不支持 PowerShell。在 Azure 管道 yml 文件中使用 PowershellCore(即scriptType: 'pscore')。
    猜你喜欢
    • 2017-08-03
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 2020-08-18
    • 2013-12-23
    • 2021-06-20
    相关资源
    最近更新 更多