Search code examples
azure-devopsyamlazure-pipelinesazure-blob-storageazure-storage

Azure DevOps Pipeline Azure File Copy Failing


My Azure DevOps Pipeline is getting the following error (actual values switched for security):

##[error]Upload to container: 'XXXXXXXX' in storage account: 'YYYYYY' with blob prefix: '' failed with error: 'AzCopy.exe exited with non-zero exit code while uploading files to blob storage.' For more info please refer to https://aka.ms/azurefilecopyreadme

This is occurring during this step:

  - task: AzureFileCopy@5
    displayName: Copy Files to CDN Origin
    inputs:
      SourcePath: 'wwwroot/*'
      azureSubscription: 'aaaaaa-bbbb-cccc-dddd-eeeeeeeeeee'
      Destination: 'AzureBlob'
      storage: 'YYYYYY'
      ContainerName: 'XXXXXXXX'

The following roles are assigned in IAM:

enter image description here

What am I missing here?

How can I solve this issue?


Solution

  • ##[error]Upload to container: 'XXXXXXXX' in storage account: 'YYYYYY' with blob prefix: '' failed with error: 'AzCopy.exe exited with non-zero exit code while uploading files to blob storage.'

    You can refer to the following points to resolve the issue.

    1.The AzureFilecopy task is using the Service Principal to access the Storage account. So you need to grant the Storage Blob Data Owner and Storage Blob Data Contributor to Service Principal instead of personal account.

    Refer to the steps to confirm the Service Principal:

    Step1: Navigate to Azure DevOps -> Project Settings -> Service Connections-> Find the service connection. Click the option: Manage Service Principal and confirm the Service Principal information.

    enter image description here

    Step2:You can grant the Storage Blob Data Owner and Storage Blob Data Contributor role to the service principal in Storage account.

    2.You can downgrade the AzureFileCopy task to version 3 and then upload the files to Storage account.

    steps:
    - task: AzureFileCopy@3
      displayName: 'AzureBlob File Copy'
      inputs:
        SourcePath: 'wwwroot/*'
        azureSubscription: xx
        Destination: AzureBlob
        storage: xx
        ContainerName: xx
        sasTokenTimeOutInMinutes: 240
    

    When you use AzureFileCopy@3, you don't need to add additional permission to service principal.