azure - 无法使用 Azure DevOps Pipeline 更新 RBAC 角色

标签 azure powershell azure-devops azure-active-directory azure-rbac

我正在使用 Azure DevOps Pipeline。

我在 Azure Devops 中创建了一个 ServiceConnection 并在其中添加了一个服务主体。

我使用的代理是“ubuntu-latest”

我在管道中创建了一个 powershell 任务

- task: AzureCLI@2        
  displayName: 'Assign Role'
  name: task_inline
  inputs:
    scriptType: 'pscore'
    azureSubscription: 'AzureConnRM'
    scriptLocation: scriptPath
    addSpnToEnvironment: true
    scriptPath: './abc.ps1'

在 Powershell 中更新现有的 RBAC 角色,我运行以下命令:

az role assignment update --role-assignment $myjson  --debug --verbose

我传递的 json 是

$myjson = '{
  "conditionVersion": "",
  "roleDefinitionName": "Contributor",
  "principalType": "User",
  "condition": "",
  "id": "/subscriptions/097ca710-067e-4a70-8ce6-494268568148/resourceGroups/Trial-RG/providers/Microsoft.Authorization/roleAssignments/45d7dc3c-4a95-8a1c-bd87-f8a460c6d255",
  "resourceGroup": "Trial-RG",
  "roleDefinitionId": "/subscriptions/097ca710-067e-4a70-8ce6-494268568148/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c",
  "type": "Microsoft.Authorization/roleAssignments",
  "scope": "/subscriptions/097ca710-067e-4a70-8ce6-494268568148/resourceGroups/Trial-RG",
  "principalId": "8cd5df22-42f4-405e-b3ab-d562eaf1da92",
  "canDelegate": "",
  "description": "Updated",
  "name": "45d7dc3c-4a95-8a1c-bd87-f8a460c6d255"
  }'

但出现错误:

错误详细信息:需要用双引号括起来的属性名称:第 2 行第 3 列(字符 4)

最佳答案

谢谢@Toni --debug 帮助我查看详细日志。 3 个字段 conditionVersion、canDelegate、condition 未正确设置。我从 json 中删除了这些属性,它起作用了。

关于azure - 无法使用 Azure DevOps Pipeline 更新 RBAC 角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73870272/

相关文章:

powershell - 使用 -NoExit 启动 PowerShell 不起作用

powershell - Powershell使用特殊字符修剪文本

azure - 有关在 Get-AzVm 中解析标签值的 Powershell 问题

c# - 在 Azure 上的 WebJob 中使用连接字符串

c# - Azure:.NET Framework(首先使用 EF 代码)和 Microsoft SQL Server 对于某些查询突然出现 CPU 峰值

powershell - 如何在powershell中使用多个值进行比较

asp.net - 如何仅发布捆绑/缩小的脚本

tfs - 如何从命令行连接到托管的 Team Foundation Service

azure-devops - 在 azure-devops 中的发布管道期间创建标签

templates - Azure DevOps 模板管道函数