Azure DevOps Pipeline 无法使用 Azure 数据工厂构建管道的 ARM 模板部署 yaml 模板

问题描述 投票:0回答:1

我正在尝试执行一个管道,该管道使用 ARM 模板部署来执行到 Azure 的管道 enter image description here

yaml脚本如下:

- task: AzureResourceManagerTemplateDeployment@3
  inputs:
    deploymentScope: 'Resource Group'
    azureResourceManagerConnection: 'NewAzureConnection'
    subscriptionId: 'xxxxxx-xxxx-xxx-xxxxxxxx03'
    action: 'Create Or Update Resource Group'
    resourceGroupName: '$(ResourceGroupUAT)'
    location: '$(Location)'
    templateLocation: 'Linked artifact'
    csmFile: '$(System.DefaultWorkingDirectory)/adf-xxxxabric-dev/ARMTemplateForFactory.json'
    csmParametersFile: '$(System.DefaultWorkingDirectory)/adf-xxxxxx-dev/ARMTemplateParametersForFactory.json'
    overrideParameters: '-factoryName $(DataFactoryUAT)'
    deploymentMode: 'Incremental'

完整脚本如下:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- adf_publish

pool:
  vmImage: ubuntu-latest
steps:
- script: |
    tree $(System.DefaultWorkingDirectory)
  displayName: Show file structure of System.DefaultWorkingDirectory during a build


- task: AzurePowerShell@5
  inputs:
    azureSubscription: 'NewAzureConnection'
    ScriptType: 'FilePath'
    ScriptPath: '$(System.DefaultWorkingDirectory)/adf-xxxxx-xxxxx-dev/PrePostDeploymentScript.ps1'
    ScriptArguments: '-armTemplate "$(System.DefaultWorkingDirectory)/adf-xxxx-xxxx-dev/ARMTemplateForFactory.json" -ResourceGroupName $(ResourceGroupUAT) -DataFactoryName $(DataFactoryUAT) -predeployment $true -deleteDeployment $false'
    azurePowerShellVersion: 'LatestVersion'

    - task: AzureResourceManagerTemplateDeployment@3
      inputs:
        deploymentScope: 'Resource Group'
        azureResourceManagerConnection: 'NewAzureConnection'
        subscriptionId: 'xxxxxx-xxxx-xxx-xxxxxxxx03'
        action: 'Create Or Update Resource Group'
        resourceGroupName: '$(ResourceGroupUAT)'
        location: '$(Location)'
        templateLocation: 'Linked artifact'
        csmFile: '$(System.DefaultWorkingDirectory)/adf-xxxxabric-dev/ARMTemplateForFactory.json'
        csmParametersFile: '$(System.DefaultWorkingDirectory)/adf-xxxxxx-dev/ARMTemplateParametersForFactory.json'
        overrideParameters: '-factoryName $(DataFactoryUAT)'
        deploymentMode: 'Incremental'

当我运行管道时,它在任务:AzureResourceManagerTemplateDeployment@3 上失败,并出现以下错误: ##[错误]检查资源组状态失败。错误:{“statusCode”:403}

enter image description here

对于导致错误的原因有什么想法吗?

ARM模板设置如下: enter image description here

azure-devops azure-pipelines azure-data-factory azure-pipelines-yaml azure-pipelines-tasks
1个回答
0
投票

错误:##[错误]检查资源组状态失败。错误:{“statusCode”:403}

该错误表示 Azure DevOps 服务连接中使用的服务主体没有足够的权限来执行该操作。

要解决此问题,您需要为服务主体添加 Azure RBAC 角色。

您可以导航至 项目设置 -> 服务连接 -> 找到您使用的服务连接 -> 选择管理服务连接角色

enter image description here

然后,它将在 Azure 门户中打开 Azure 订阅页面,导航到 访问控制 (IAM) -> 将服务主体添加为 Contributor 角色。

然后您可以重新运行 Pipeline 以在 Azure Pipeline 中部署 ARM 模板。

注意: 要为您的服务主体分配角色,您的用户帐户需要具有 RBAC 角色,例如所有者用户访问管理员

© www.soinside.com 2019 - 2024. All rights reserved.