azure - 如何使用 ARM 模板将文件从主存储库上传到文件共享?

标签 azure azure-devops azure-pipelines azure-pipelines-yaml

我有一个用于创建存储帐户和文件共享的模板。像这样:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.5.6.12127",
      "templateHash": "3186185032530874094"
    }
  },
  "parameters": {
    "storageAccountName": {
      "type": "string",
      "defaultValue": "[format('storage{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Specifies the name of the Azure Storage account."
      }
    },
    "fileShareName": {
      "type": "string",
      "maxLength": 63,
      "minLength": 3,
      "metadata": {
        "description": "Specifies the name of the File Share. File share names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Specifies the location in which the Azure Storage resources should be deployed."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-04-01",
      "name": "[parameters('storageAccountName')]",
      "location": "[parameters('location')]",
      "kind": "StorageV2",
      "sku": {
        "name": "Standard_LRS"
      },
      "properties": {
        "accessTier": "Hot",
        "minimumTlsVersion"  : "TLS1_2",
        "supportsHttpsTrafficOnly": "true"
      }
    },
    {
      "type": "Microsoft.Storage/storageAccounts/fileServices/shares",
      "apiVersion": "2021-04-01",
      "name": "[format('{0}/default/{1}', parameters('storageAccountName'), parameters('fileShareName'))]",
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      ]
    }
  ]
}

最佳答案

在 YAML 管道中,您正在使用 AzureFileCopy@4 任务。

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

从错误消息来看,导致此问题的原因可能是服务连接创建的服务主体没有足够的权限将文件复制到 Azure 存储帐户。

请参阅以下步骤查找服务主体并将存储 Blob 数据所有者和存储 Blob 数据贡献者添加到服务主体。

第 1 步:导航到 Azure 门户 -> AAD -> 应用注册以查找相关的服务主体。

第 2 步:导航到存储帐户并将存储 Blob 数据所有者和存储 Blob 数据贡献者授予服务主体。

更详细的步骤,可以引用这个文档:Assign an Azure role for access to blob data

或者您可以更改为使用 AzureFileCopy@3 来替换 AzureFileCopy@4。您可以检查一下是否可以工作。

关于azure - 如何使用 ARM 模板将文件从主存储库上传到文件共享?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73066582/

相关文章:

azure - 使用 az cli 将贡献者角色分配给应用程序

reactjs - 如何在React中的Azure B2C流程中获取无到期刷新 token

reactjs - Azure 应用服务中没有为静态文件注册路由

azure-devops - 如何在 Azure DevOps 的工件部分显示管道工件

continuous-integration - 构建后 VSTS 触发器发布和部署

azure - Microsoft Teams 通知间歇性停止工作

azure - Azure管道中的Cypress构建错误: Cannot find module '@cypress/code-coverage/task'

azure - 在 Power BI 中显示 Azure 流的当前(最新)值

azure - 如何在 Azure DevOps 发布管道中保存测试结果

node.js - Webpack @azure/storage-blob node-fetch AbortSignal 问题